Skip to content

getSymbols: catch errors and continue processing #135

Closed
@joshuaulrich

Description

Wrap download.file() in a try() or tryCatch() in order to catch errors and provide more useful messages to the user.

For example, Google Finance does not provide historical data for the S&P 500 index, even though it's displayed on their website. Note there's no "Export/Download to spreadsheet" link under the historical chart like there are for symbols where getSymbols.google() works (e.g. General Electric).

R> getSymbols(".INX", src = "google")
Error in download.file(paste(google.URL, "q=", Symbols.name, "&startdate=",  : 
  cannot open URL 'http://finance.google.com/finance/historical?q=.INX&startdate=Jan+01,+2007&enddate=Jan+21,+2017&output=csv'
In addition: Warning message:
In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=",  :
  cannot open URL 'http://finance.google.com/finance/historical?q=.INX&startdate=Jan+01,+2007&enddate=Jan+21,+2017&output=csv': HTTP status was '404 Not Found'

It would also be nice if a download.file() error did not completely stop getSymbols() when getSymbols() is called with multiple symbols.

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions