From 5b1aa7d8a0e55690174cfb310e72d94348194e5b Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Wed, 11 Apr 2018 11:38:57 -0500 Subject: [PATCH] Catch and warn on getSymbols.yahooj() errors Use the same logic as getSymbols.yahoo(). See #135. --- R/getSymbols.R | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/R/getSymbols.R b/R/getSymbols.R index 1d630509..00afa03e 100644 --- a/R/getSymbols.R +++ b/R/getSymbols.R @@ -438,7 +438,11 @@ function(Symbols,env,return.class='xts',index.class="Date", stop("package:",dQuote("XML"),"cannot be loaded.") yahoo.URL <- "https://info.finance.yahoo.co.jp/history/" - for(i in 1:length(Symbols)) { + + returnSym <- Symbols + noDataSym <- NULL + for(i in seq_along(Symbols)) { + test <- try({ # The name of the symbol, which will actually be used as the # variable name. It needs to start with YJ, and it will be appended # if it does not. @@ -565,9 +569,16 @@ function(Symbols,env,return.class='xts',index.class="Date", Sys.sleep(1) } + }, silent = TRUE) + if (inherits(test, "try-error")) { + msg <- attr(test, "condition")$message + warning("Unable to import ", dQuote(returnSym[[i]]), ".\n", + msg, call. = FALSE, immediate. = TRUE) + noDataSym <- c(noDataSym, returnSym[[i]]) + } } if(auto.assign) - return(Symbols) + return(setdiff(returnSym, noDataSym)) return(fr) } # }}}