[R] character string as object name

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Mar 5 16:34:56 CET 2009


b is character string:

> as.name(b)
`MSFT$MSFT.Adjusted`

Note the backticks: that is a valid (if non-syntatatic) name, but you 
don't have an object of that name.

On Thu, 5 Mar 2009, Fuchs Ira wrote:

> Can someone please tell me why the following (last line) doesn't work (as I 
> expect it to :-)

The question is rather why you are misinformed about how it works.
Since you didn't explain how you think it does work, we have little 
idea what your error was.  If it helps,

MSFT$MSFT.Adjusted

is a call (to `$`).

It also helps to explain what you are trying to do rather than just 
what you did.

>
> library(quantmod)
> a = getSymbols("MSFT",from="2009-3-01")
> a
> MSFT
> eval(as.name(a))
> MSFT$MSFT.Adjusted
> b=paste(a,'$MSFT.Adjusted',sep='')
> b
> eval(as.name(b))
>
> Why does this last line not work the way the earlier eval does?
>
> Thanks.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list