[R] need help for eval()

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Sep 21 16:21:39 CEST 2002


demolombe wrote:
> 
> Hello,
> 
> I need help, after hours trying to do it myself,
> to do the following:
> 
>     I have an object, named, say,  F1   from a class "fichier"  that I buildt.
>     this F1 has a slot named datas   ,which is a vector, so I can access to
> : F1 at datas[1], F1 at datas[2], ...
> 
>     Now I have a string s="F1 at datas[1]" and need to retreive the real
> content of F1 at datas[1] using s.
> 
>     Is there a way to do this, as it is in Matlab?


E.g., you'll get the value by 
1) coercing the string to an expression, and
2) evaluating that one.

 eval(parse(text = s))

You can get access to particular slots by slot(), but that's another
topic, since your character string describes much more than that.

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list