Reputation: 175
I've tried to get dividends from R and I get an error. Here is the codes that I use:
library(xts)
library(quantmod)
Tick <- c("A","AA","AADR","AAN","AAP") #have more than 3 thousands symbols.
divs <- xts()
for( sym in Tick) {
divs <- merge(divs, getDividends(sym, from= "2016-01-04", to="2017-03-09", src="yahoo"))
}
The error I have is:
Error in open.connection(file, "rt") :
Handle is already in use elsewhere.
I googled about this error, but I couldn't figure out where it came from. Anybody know why?
Upvotes: 0
Views: 162
Reputation: 388982
Try using lapply
:
library(quantmod)
result <- Reduce(merge, lapply(Tick, function(x) {
tryCatch({
getDividends(x, from= "2016-01-04", to="2017-03-09", src="yahoo")
}, error = function(e) {}
)
}))
Upvotes: 1