现在整个世界都在努力使用SSL(这个决定很有意义)我们中的一些人使用github和相关服务来存储csv文件有一点挑战.从URL读取时,read.csv()函数不支持SSL.为了解决这个问题,我正在做一个小舞蹈,我喜欢称之为SSL歌舞伎舞蹈.我用RCurl抓取文本文件,将其写入临时文件,然后用read.csv()读取它.这样做有更顺畅的方法吗?更好的解决方案?
这是SSL kabuki的一个简单示例:
require(RCurl)
myCsv <- getURL("https://gist.github.com/raw/667867/c47ec2d72801cfd84c6320e1fe37055ffe600c87/test.csv")
temporaryFile <- tempfile()
con <- file(temporaryFile, open = "w")
cat(myCsv, file = con)
close(con)
read.csv(temporaryFile)
Run Code Online (Sandbox Code Playgroud)
Sea*_*ean 14
无需将其写入文件 - 只需使用textConnection()
require(RCurl)
myCsv <- getURL("https://gist.github.com/raw/667867/c47ec2d72801cfd84c6320e1fe37055ffe600c87/test.csv")
WhatJDwants <- read.csv(textConnection(myCsv))
Run Code Online (Sandbox Code Playgroud)
JD *_*ong 12
使用Dirk的建议进行探索method=""
导致这种稍微更简洁的方法,而不依赖于外部RCurl包.
temporaryFile <- tempfile()
download.file("https://gist.github.com/raw/667867/c47ec2d72801cfd84c6320e1fe37055ffe600c87/test.csv",destfile=temporaryFile, method="curl")
read.csv(temporaryFile)
Run Code Online (Sandbox Code Playgroud)
但似乎我不能只是设定 options("download.file.method"="curl")
是的 - 看看help(download.file)
哪个read.csv()
堂兄指出了哪个.method=
那里的论点有:
method
用于下载文件的方法.目前可以使用下载方法"internal","wget","curl"和"lynx",并且有一个值"auto":参见"Details".该方法也可以通过选项"download.file.method"进行设置:参见options().
然后使用此选项options()
:
download.file.method:
用于download.file的方法.目前可以使用下载方法"内部","wget"和"lynx".当选择method ="auto"时,此选项没有默认值:请参阅download.file.
转向外部程序 curl
,而不是RCurl包.
编辑:看起来我是半正确的,一半是错的.read.csv()
等人不使用所选择的方法,需要手动使用download.file()
(然后使用curl
或其他选择的方法).其他正在使用的功能download.file()
(例如包安装或更新)将从设置选项中获益,但对于JD关于https的csv文件的初始查询,在下载文件download.file()
之前需要显式read.csv()
.
R core应该将R连接作为C API打开.我过去提过这个:
https://stat.ethz.ch/pipermail/r-devel/2006-October/043056.html
没有回应.