The issue is that by default getSymbols
assigns the data in the parent.frame()
. When you call getSymbols()
from a function, the parent.frame()
is no longer the .GlobalEnv
that you're used to. So, a quick fix to your current could would be to replace
l_ply(symbols, function(sym) try(getSymbols(sym)))
with
l_ply(symbols, function(sym) try(getSymbols(sym, env=globalenv())))
Note that you may run into trouble at the next step where you use get
. You should probably also specify which environment you want to get
the data from so that it would also work if you put it in a function. i.e. sym.list <- llply(symbols, get, pos=globalenv())
Here's a more common idiom for getting and merging data with quantmod
library(quantmod)
s <- c("MSFT","C","MMM")
e <- new.env() #environment in which to store data
getSymbols(s, src="yahoo", env=e)
do.call(merge, eapply(e, Cl)[s])
Or, using try
like the OP
L <- lapply(symbols, function(sym) try(getSymbols(sym, auto.assign=FALSE)))
do.call(merge, lapply(L, Cl))