简体   繁体   中英

I get an error from R when I run quantmod (getDividens)

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?

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) {}
  )
}))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM