k-zar k-zar - 5 days ago 6
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

We can use deparse

deparse(myObject)
#[1] "c(1, 2, 3)"
Comments