I have been using the following script in RStudio and as a PowerBI script successfully but I will intermittently get an error when BatchGetSymbols runs.
Following is the script
if (!require(BatchGetSymbols)) install.packages('BatchGetSymbols')
if (!require(rio)) install.packages('rio')
library(BatchGetSymbols)
first.date = Sys.Date() - 1460
last.date = Sys.Date()
tickers <- c('SPY', '^GSPC')
l.out <- BatchGetSymbols(tickers = tickers,
first.date = first.date,
last.date = last.date,
cache.folder = "C://users/owner/documents/r/BGS_Cache")
if (!require(ggplot2)) install.packages("ggplot2")
library(ggplot2)
p <- ggplot(l.out$df.tickers, aes(x = ref.date, y = price.close))
p <- p + geom_line()
p <- p + facet_wrap(~ticker, scales = 'free_y')
print(p)
tickers<- as.data.frame(l.out)
library(rio)
write.table(tickers,file="Tickers.csv",sep=",")
The error returns the following
Running BatchGetSymbols for:
tickers = SPY, ^GSPC
Downloading data for benchmark ticker | Found cache file | Need new data Error in charToDate(x) :
character string is not in a standard unambiguous format
Is there any way to trap this error from preventing the script to execute?
Thanks and Regards
Jim B