Can someone please tell me why the following (last line) doesn't work (as I expect it to :-) 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.
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
Does the first item on page 52 of 'The R Inferno' explain it for you? If not, can you give some hints about how to improve the explanation? Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") Fuchs Ira wrote:> Can someone please tell me why the following (last line) doesn't work > (as I expect it to :-) > > 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. > >
Fuchs Ira wrote:> Can someone please tell me why the following (last line) doesn't work > (as I expect it to :-) > > 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? >because eval(as.name(b)) looks for `MSFT$MSFT.Adjusted`, not for `MSFT`$`MSFT.Adjusted`: 'MSFT$MSFT.Adjusted' = 'rubbish' eval(as.name(b)) # "rubbish" vQ