【问题标题】:read.xls and url on Windows in RR 中 Windows 上的 read.xls 和 url
【发布时间】:2016-10-08 21:13:18
【问题描述】:

我在这里看到了很多关于使用带有 url 的 read.xls 的帖子,它们都在我的 Mac 上运行,但是现在当我尝试在我的 Windows 计算机上使用代码时,它不起作用。我在我的 Mac 上使用了以下代码:

tmp <- tempfile()
download.file("https://www.spdrs.com/site-content/xls/SPY_All_Holdings.xls?fund=SPY&docname=All+Holdings&onyx_code1=1286&onyx_code2=1700", destfile = tmp, method = "curl")
SPY <- read.xls(tmp, skip=3)

unlink(tmp)

不再使用“curl”(“had status 127”是警告消息),当我尝试“internal”或“wininet”时,它显示“formal argument”method”matched by multiple actual arguments”。当我尝试 read.xls 时,它说文件“丢失”和“无效”。我已经下载了 Perl、Java、gdata、Rcurl 和“下载器”包(因为我听说它与 https 配合得更好)并且可以使用它来代替....在 Windows 计算机上我还需要做些什么吗?这段代码有效吗?

谢谢!

【问题讨论】:

  • data&lt;- read.xls(file.choose(),perl="C:/Perl64/bin/perl.exe")read.xls 函数的perl 参数中找到您的perl.exe 文件。对于read.xls() 函数,您需要在R 中安装gdata() 包。为perl.exe 路径设置环境变量也会有所帮助。
  • 给我们命令直到现在你尝试了 WIndows 机器及其输出或它抛出的错误..
  • 我看到了这个链接。看看这是否有帮助:stackoverflow.com/questions/21738463/…
  • @SowmyaS.Manian 我看到了这个问题,并认为这意味着手动将 https 更改为 http。理想情况下,我正在尝试使整个过程自动化
  • stackoverflow.com/questions/24165623/… 此处找到的代码有效!

标签: r windows macos xls


【解决方案1】:
> library(RCurl)
> library(XLConnect)
> URL <- "https://www.spdrs.com/site-content/xls/SPY_All_Holdings.xls?fund=SPY&docname=All+Holdings&onyx_code1=1286&onyx_code2=1700"
> f = CFILE("SPY_All_Holdings.xls", mode="wb")
> curlPerform(url = URL, writedata = f@ref, ssl.verifypeer = FALSE)
# OK 
# 0 
> close(f)
# An object of class "CFILE"
# Slot "ref":
# <pointer: (nil)>

> out <- readWorksheetFromFile(file = "SPY_All_Holdings.xls",sheet="SPY_All_Holdings")
> head(out)
#           Fund.Name. SPDR..S.P.500..ETF     Col3                   Col4        Col5
# 1          Ticker Symbol:                SPY     <NA>                   <NA>         <NA>
# 2               Holdings:   As of 06/06/2016     <NA>                   <NA>         <NA>
# 3                    Name         Identifier   Weight                 Sector  Shares Held
# 4              Apple Inc.               AAPL 2.945380 Information Technology 54545070.000
# 5   Microsoft Corporation               MSFT 2.220684 Information Technology 77807630.000
# 6 Exxon Mobil Corporation                XOM 1.998224                 Energy 40852760.000

【讨论】:

  • 嘿,您同时发现了相同的链接。我在检查它是否对你有用。太好了!!!
猜你喜欢
  • 2014-06-25
  • 1970-01-01
  • 2018-10-05
  • 2014-03-11
  • 2018-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多