k-zar k-zar - 10 months ago 59
R Question

R function to convert object into code

I am looking for a function in R that converts an object into code that can be used to create a replica of that object. Something like this:

> myObject=c(1, 2, 3)
> magicFunction(myObject)
[1] "c(1,2,3)"

I think this function exists, but I cannot find it. Would greatly appreciate your help.

Answer Source

We can use deparse

#[1] "c(1, 2, 3)"