I am looking for a function to get the code generating a data frame in R. I haven't found any simple function that would allow me to do this. Of course I could hard code something to do it. I was wondering if there were any shortcut or built-in t do that.
mydata = data.frame(x=c("A","A","B"),y=c(1,2,1))
Input:
mydata
x y
1 A 1
2 A 2
3 B 1
Ouput:
dfToCode(mydata)
"data.frame(x=c("A","A","B"),y=c(1,2,1))"
I know it is a little unconventional and that it would be better to store the data frame in a file.
Anyway a function like this would allow me to get a reproducible example of a small data frame easily within my code.
Thank you
No comments:
Post a Comment