How to reconstruct R objects without writing them in a file?

98 views Asked by At

I have R object which is to be shared with another analyst. I write:

dput(objectname,"filename.R")

and then the object can be reconstructed by sharing the .R file and using the dget(filename.R) function. Now what I want to do is just share the object structure and not the file. Is it possible? I tried the following:

a <- dput(b)
structure(1:50, .Dim = c(10L, 5L))

But cannot reconstruct this object. All I get is :

dget(a)
?
1

There are 1 answers

0
Jilber Urbina On BEST ANSWER
> a <- dput(b)
structure(1:50, .Dim = c(10L, 5L))
> a  # 'reconstructing' b
      [,1] [,2] [,3] [,4] [,5]
 [1,]    1   11   21   31   41
 [2,]    2   12   22   32   42
 [3,]    3   13   23   33   43
 [4,]    4   14   24   34   44
 [5,]    5   15   25   35   45
 [6,]    6   16   26   36   46
 [7,]    7   17   27   37   47
 [8,]    8   18   28   38   48
 [9,]    9   19   29   39   49
[10,]   10   20   30   40   50

Note that after dputting b and assigning it to a a message is displayed, to recover b, just print a.