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

blue sky bluesky315 at gmail.com
Fri Feb 12 17:11:20 CET 2010


On Fri, Feb 12, 2010 at 1:38 AM, Sharpie <chuck at sharpsteen.net> wrote:
>
>
> 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.

Since there is no solution to my original question. Let me change it a
bit and see if there is a solution.

Rscript essentially parse the R file. I have no idea how Rscript
works. Do you know how to modify it to spit out the original code for
the assignment of a variable?



More information about the R-help mailing list