Output a vector in R in the same format used for inputting it into R

r

Solution

`dput` maybe?

> test <- c(1,2,3)
> dput(test)
c(1, 2, 3)

You can also `dump` out multiple objects in one go to a file that is written in your working directory:

> test2 <- matrix(1:10,nrow=2)
> test2
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10
> dump(c("test","test2"))

`dumpdata.r` will then contain:

test <-
c(1, 2, 3)
test2 <-
structure(1:10, .Dim = c(2L, 5L))

Problem

Maybe I'm imagining this, but I think there is a built-in R function that lets you print an R vector (and possibly other objects like matrices and data frames) in the format that you would use to enter that object (returned as a string). E.g., ``` > x <- c(1,2,3) > x [1] 1 2 3 > magical.function(x) "c(1,2,3)" ``` Does this function exist?

Original source