[R] Change value of a slot of an S4 object within a method.

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Aug 25 21:36:53 CEST 2010


On Wed, Aug 25, 2010 at 1:21 PM, Joris Meys <jorismeys at gmail.com> wrote:
> Hi Steve,
> thanks for the tip.  I'll definitely take a closer look at your
> solution for implementation for future use.  But right now I don't
> have the time to start rewriting my class definitions.
> Luckily, I found where exactly things were going wrong. After reading
> into the documentation about the evaluation in R, I figured out I have
> to specify the environment where substitute should look explicitly as
> parent.frame(1). I still don't understand completely why exactly, but
> it does the job.
> Thus :
> eval(eval(substitute(expression(object at extra[[name]] <<- value))))
> should become :
> eval(
>   eval(
>      substitute(
>         expression(object at extra[[name]] <<- value)
>      ,env=parent.frame(1) )
>   )
> )

My eyes start to gloss over on their first encounter of `substitute`
... add enough `eval`s and (even) an `expression` (!) to that, and
you'll probably see me running for the hills ... but hey, if it makes
sense to you, more power to you ;-)

Glad you found a fix that works,


Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

More information about the R-help mailing list