Creating a reproducible read_csv example



I want to ask a question about using read_csv. To create a small, reproducible example, you’d think that requires an example CSV file. Is that what you’d do, and upload it? Or is there a nifty way to create a small dataframe in code (e.g. with dput) and simulate reading it in using read_csv?


And having created an example csv file, you’re not allowed to upload that file type. So that seems to nitch that idea.


I’m an idiot. I’ve used this before and just remembered. You can pass a string containing newlines thus:

problem_data <- read_csv("ID, Type, Value\n1, 27, Startup\n2, 28, Load system\n3, 28, Initialise system\n4, 10, Processing data\n5, 10, Processed data, written result to file\n6, 30, Shutdown")