Saturday, March 2, 2019

r - Function returning the code to create a dataframe

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...