read.csv(“http://ichart.finance.yahoo.com/table.csv?s=SPY”) Not Working

試著忘記壹切 提交于 2019-12-19 10:16:36

问题


I have been using the following command for a long time without problem:

spy <- read.csv("http://ichart.finance.yahoo.com/table.csv?s=SPY")

But in the past few days it started to throw the following error:

Warning messages:

1: In file(file, "rt") : "internal" method cannot handle https redirection to: 'https://ichart.finance.yahoo.com/table.csv?s=SPY'

2: In file(file, "rt") : "internal" method failed, so trying "libcurl"

I've updated my RStudio, R and all packages to the most up-to-date versions as of today. Could someone help me resolve this issue?

Thanks in advance!


回答1:


The fix is right there in the error message: use https not http:

R> spy <- read.csv("https://ichart.finance.yahoo.com/table.csv?s=SPY")
R> head(spy)
        Date   Open   High    Low  Close   Volume Adj.Close
1 2017-04-19 234.52 234.95 233.18 233.44 66861500    233.44
2 2017-04-18 233.72 234.49 233.08 233.87 80188300    233.87
3 2017-04-17 233.11 234.57 232.88 234.57 63559500    234.57
4 2017-04-13 233.64 234.49 232.51 232.51 83019800    232.51
5 2017-04-12 234.74 234.96 233.77 234.03 76322100    234.03
6 2017-04-11 234.90 235.18 233.34 235.06 85727700    235.06
R> 



回答2:


And if you are using the function getReturns from the stockPortfolio package, use the modified getReturns function in the link below:

https://gist.github.com/Maiae/46a058243819ae0973fd38708a32fc31

It basically replaces http:// with https://




回答3:


Yahoo stoped service if you want to run with small dataset download csv from here and use

https://github.com/datasets/s-and-p-500-companies



来源:https://stackoverflow.com/questions/43529918/read-csvhttp-ichart-finance-yahoo-com-table-csvs-spy-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!