Reputation: 2301
I am using the quantmod R package. Is there a way to have getSymbols return a generic xts object instead of the symbol I am getting. For instance, if I have execute:
getSymbols("COKE", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1990-01-01')
It creates the xts object in the name of symbol COKE. As said, is there a way to return a xts data object to a generic variable like x. I.e.
x <- getSymbol(...)
I am have looked high and low for a solution but no answers.
Thanks
Upvotes: 3
Views: 2484
Reputation: 28913
If getSymbols() didn't already offer the auto.assign parameter, the other way to do it is like this:
ret <- getSymbols("COKE", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1990-01-01')
x <- get(ret)
And if you didn't want COKE polluting your environment, look into green energy. ...sorry, bad joke. What you can do, to clean up, is this:
rm(list=ret);rm(ret)
(But this is just by the by, Joshua's answer is of course the correct one.)
Upvotes: 0
Reputation: 176648
It's in ?getSymbols
(emphasis added):
Value:
A call to getSymbols will load into the specified environment one object for each ‘Symbol’ specified, with class defined by ‘return.class’. Presently this may be ‘ts’, ‘its’, ‘zoo’, ‘xts’, or ‘timeSeries’.
If ‘auto.assign’ is set to FALSE an object of type ‘return.class’ will be returned.
For example:
x <- getSymbols("COKE", auto.assign=FALSE)
Before looking high and low, it's a good idea to read and understand the documentation. ;-)
Upvotes: 7