Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating R object based on dput() - recreating other people's data

Tags:

r

Say I am reading a post where someone has included example data dput(). Is there a method to recreate that data by copying and pasting the dput output?

For example:

dput(analysis)

structure(c("1", "2", "3", "95", "76", "73", "3.9 [3, 4.7]", 
"3.9 [2.9, 4.9]", "3.9 [2.9, 4.9]", "-0.149364093194283", "-0.0634756995556436", 
"-0.0800909978288318", "8 [7, 9]", "8.2 [7.2, 9.3]", "8.3 [7.2, 9.3]", 
"0.000201414878031159", "0.214881972259157", "0.268328556507466"
), .Dim = c(3L, 6L), .Dimnames = list(NULL, c("Module", "Individuals", 
"y1 [95CI]", "y1 - mu", "y2 [95CI]", "y2 - mu")))

Is there a simpler way to reproduce this instead of manually creating multiple vectors, naming them etc?

I'm interested in the method behind this, as I feel it would save time when recreating people's shared data e.g. when answering other people's stackoverflow questions.

like image 599
MBorg Avatar asked Aug 31 '25 02:08

MBorg


1 Answers

Turns out the answer is quite mundane. Simply assigning the dput output a variable does the trick.

For example:

m <- dput(structure(c("1", "2", "3", "9532", "6968", "6637", "4 [3.9, 4.1]", 
                       "4 [3.9, 4.1]", "4 [3.9, 4.1]", "0.0187143916545995", "0.00863901324167671", 
                       "0.00960376951904252", "8 [7.9, 8.1]", "8 [7.9, 8.1]", "8 [7.9, 8.1]", 
                       "0.0187528128796863", "0.00481608674854073", "0.0173215731030023"
), .Dim = c(3L, 6L), .Dimnames = list(NULL, c("Module", "Individuals", 
                                              "y0 [95CI]", "y0 - mu", "y1 [95CI]", "y1 - mu")))
)
like image 71
MBorg Avatar answered Sep 02 '25 14:09

MBorg