[R] How to get the source code for the assignment of a variable?

Sharpie chuck at sharpsteen.net
Fri Feb 12 08:38:16 CET 2010



djhurio wrote:
> 
> I believe there is not such thing as source code for a variable. I believe
> if you define x=y*y, x is keeping only the values of y*y, but not how they
> were computed. Am I right?
> 

In general yes.  Basic variables do not store a copy of the function call
that created them.

However, some objects have been build to store a memory of how they were
created.  Take for example a linear model:

    model <- lm( demand ~ Time, data = BOD )

One of the components of the `model` variable is called call and it stores a
language object that is a copy of the lm function call that was used to
generate `model`:

> model$call
lm(formula = demand ~ Time, data = BOD)

This object could be passed to the eval() function to basically re-run the
operation that generated `lm`.

The str() function can be used to discover what sorts of tidbits may be
hiding inside a variable.


Hope this helps!


-Charlie

-- 
View this message in context: http://n4.nabble.com/How-to-get-the-source-code-for-the-assignment-of-a-variable-tp1478140p1478220.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list