When creating a reproducible example I often want to output a data.frame
or similar using put()
:
my_data <- structure(list(pr_id = c("X1626", "X1689", "X1818", "X2044",
"X1572"), t1 = c("PID", "WRC", "PID", "PID", "PID"), t2 = c("PRO",
"DEC", "ECV", "PRO", "PRO"), t3 = c("REF", "", "ECV", "SMK",
"REF"), t4 = c("ECV", "", "ECV", "SMK", "SMK"), t5 = c("SMK",
"", "ECV", "ECV", "SMK"), t6 = c("SMK", "", "SMK", "", "TEA"),
t7 = c("DEC", "", "DEC", "", "SMK"), t8 = c("", "", "REF",
"", "SMK"), t9 = c("", "", "SMK", "", "TEA"), t10 = c("",
"", "", "", "SMK"), t11 = c("", "", "", "", "SMK"), t12 = c("",
"", "", "", "SMK"), t13 = c("", "", "", "", "SMK"), t14 = c("",
"", "", "", "DEC")), .Names = c("pr_id", "t1", "t2", "t3",
"t4", "t5", "t6", "t7", "t8", "t9", "t10", "t11", "t12", "t13",
"t14"), row.names = c(NA, 5L), class = "data.frame")
However, when I try to load the data it asks me for a file:
my_data_loaded <- dget(my_data)
Error in parse(file = file, keep.source = keep.source) :
'file' must be a character string or connection
How can I easily create a dput
and then load it back in again in order to create a script that is a reproducible example? I want to avoid saving it as a file, and simply run the entire thing as a script.