-2
yahoo<-function(sym,current = TRUE, a=0,b=1,c=2000,d,e,f,g="d")
{
  if(current){
  f<-as.numeric(substr(as.character(Sys.time()),start = 1,stop = 4))
  d<-as.numeric(substr(as.character(Sys.time()),start = 6,stop = 7))-1
  e<-as.numeric(substr(as.character(Sys.time()),start = 9,stop = 10))
}
  require(data.table)
  tryCatch(
  suppressWarnings(
  fread(paste0("http://ichart.yahoo.com/table.csv",
                   "?s=",sym,
                   "&a=",a,
                   "&b=",b,
                   "&c=",c,
                   "&d=",d,
                   "&e=",e,
                   "&f=",f,
                   "&g=",g,
                   "&ignore=.csv"),sep=",")),
    error = function(e) NULL
  )
}

When I run Google<-yahoo("GOOG"), this is the message I received:

trying URL 'http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2000&d=8&e=13&f=2017&g=d&ignore=.csv' Content type 'text/html; charset=utf-8' length unknown downloaded 1078 bytes

So how to change that function make it work?

1 Answers1

0

This code isn't working because the Yahoo Finance web service which you're trying to access was discontinued in May 2017. You will need to find another source for this data.