How to export data in R syntax? Given a data frame in R is there a way to export it in R syntax such that executing this code would re-create the data frame? I would find this useful to store results in R files along with calculations without depending on external files.
 A: You can use dput() to get a structure() that can be used later.
> #Build the original data frame
> x <- seq(1, 10, 1)  
> y <- seq(10, 100, 10)  
> df <- data.frame(x=x, y=y)   
> df   
    x   y
1   1  10
2   2  20
3   3  30
4   4  40
5   5  50
6   6  60
7   7  70
8   8  80
9   9  90
10 10 100

> #Use the dput() statement to print out the structure of df
> dput(df)   
structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), y = c(10, 
20, 30, 40, 50, 60, 70, 80, 90, 100)), .Names = c("x", "y"), row.names = c(NA, 
-10L), class = "data.frame")

The above structure statement is the output of dput(df).   If you copy/paste that into your R text file, you can use it later.   Here's how.
> #Build a new dataframe from the structure() statement
> newdf <- structure(list(x = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), y = c(10, 
20, 30, 40, 50, 60, 70, 80, 90, 100)), .Names = c("x", "y"), row.names = c(NA, 
-10L), class = "data.frame")
> newdf
    x   y
1   1  10
2   2  20
3   3  30
4   4  40
5   5  50
6   6  60
7   7  70
8   8  80
9   9  90
10 10 100

