1

I always have a little problem, providing a little minimal working example to you at stack overflow.

Is there a way to print, for example a data frame, so I can copy and paste it into the R console again and create the same kind of variable?

so basically something like this:

awesomePrint(df)
df <- data.frame(
  x = c(1, 2, 3, 4),
  y = c(2, 3, 4, 5)
)
drmariod
  • 11,106
  • 16
  • 64
  • 110
  • 2
    Just try `dput(df)`. The function you are looking for is `dput`. – nicola Jul 28 '15 at 08:02
  • Thank you @nicola, could you post an answer so I can mark it as solved. – drmariod Jul 28 '15 at 08:03
  • 1
    @drmariod You should definitely read the FAQ [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) where, among other very useful things, `dput` is described. – Henrik Jul 28 '15 at 08:34

1 Answers1

1

You are looking for the dput function, that prints the command you need to recreate an object.

 df<-data.frame(x = c(1, 2, 3, 4),y = c(2, 3, 4, 5))
 dput(df)

You can also use dump to write that line on a file or on the standard output:

 dump("df","")
nicola
  • 24,005
  • 3
  • 35
  • 56