[R] selections using text strings (result of noquote)

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Jun 3 08:34:46 CEST 2002



Robert Cunningham wrote:
> 
> G'day all,
> 
> I am trying to use a string as an argument in a selection but things are
> not working as I expect, seems the selection is not seeing the expanded
> string and I do not know how to make it. Perhaps the noquote class value
> that is returned is the problem.
> 
> Here is an example.
> 
> > selection #this is my string
> [1] "attackprogress$Se=='Toona ciliata [19825: JMM35]'"
> > noquote(selection) #if I do this I get a string that if I paste into
> [] works fine
> [1] attackprogress$Se=='Toona ciliata [19825: JMM35]'
> > attackprogress$No[attackprogress$Se=='Toona ciliata [19825: JMM35]']
> #this is fine
>   [1]  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
> 0  0  0
>  [26]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
> 0  0  0
>  [51]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  3  0  0  0  0  0  0
> 0  0  0
>  [76]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  4  4  3  3  2  1  1
> 1  4  2
> [101]  0  1  2  0  1  1  1  2  3  2  2  3  0  1  1  0  0  0  0  0  3  1
> 2  4  4
> [126]  1  1  1  1  1  0  3  2  1  1  2  1  2  1  2  2  3  0  1  1  1  0
> 1  0  0
> [151]  3  3  1  2  3  3  1  1  1  1  1  1  1  0  1  2  1  3  3  2  1  4
> 1  2  2
> [176]  1  0  0  0  1  2  4  0  3  0  3  2  2  2  1  2  3  2  1  2  2  2
> 3  4  3
> [201]  1  3  1  3  4  1  0  0  0  2  2  4  3  2  4  2  4 10  5  2  3  1
> 2  1  3
> [226]  3  4  4  3  2  2  1  3  3  0  1  1  1  4  3  4  5  5  5  3  2  2
> 5  1  2
> [251]  2  1  1  6  2  5  6  5  2  2  1  2  4  0  1  2  1  1  6  4  5  3
> 5  4  7
> [276]  7  5  7  5  5  4  4  6  1  6  7  5  3  6  1  9  6  3  4  1  2  1
> 7  3  5
> [301]  3  4  5  7  7 10  3 10  5  7  5  5  5  3  1  3  3  2  4  3  1  2
> > attackprogress$No[noquote(selection)] #this is not

Now it is a "noquoted" string, but you need an expression ...

Try:

  attackprogress$No[eval(parse(text = selection))]

parse() "converts" the "selection" string to an expression, and eval()
evaluates it ....

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