使用download.file()从HTTPS下载文件 [英] Download a file from HTTPS using download.file()
本文介绍了使用download.file()从HTTPS下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 download.file()
从R读取在线数据,如下所示。
URL< - https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv
download.file(URL,destfile =./data/data .csv,method =curl)
有人建议我添加 setInternet2(TRUE)
,但它仍然无法工作。
我得到的错误是:
警告消息:
1:运行命令'curl'https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv -o./data/data.csv'had status 127
2:在download.file(URL,destfile =./data/data.csv,method =curl,:
下载有非零退出状态
感谢您的帮助。
> #install.packages(RCurl)
library(RCurl)
URL< - https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv
x < - getURL(URL)
##或
## x < - getURL(URL,ssl.verifypeer = FALSE)
out< - read.csv (textConnection(x))
head(out [1:6])
#RT SERIALNO DIVISION PUMA REGION ST
#1 H 186 8 700 4 16
#2 H 306 8 700 4 16
#3 H 395 8 100 4 16
#4 H 506 8 700 4 16
#5 H 835 8 800 4 16
#6 H 989 8 700 4 16
dim(out)
#[1] 6496 188
download.file(https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv ,destfile =reviews.csv,method =libcurl)
I would like to read online data to R using download.file()
as shown below.
URL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
download.file(URL, destfile = "./data/data.csv", method="curl")
Someone suggested to me that I add the line setInternet2(TRUE)
, but it still doesn't work.
The error I get is:
Warning messages:
1: running command 'curl "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv" -o "./data/data.csv"' had status 127
2: In download.file(URL, destfile = "./data/data.csv", method = "curl", :
download had nonzero exit status
Appreciate your help.
解决方案
It might be easiest to try the RCurl package. Install the package and try the following:
# install.packages("RCurl")
library(RCurl)
URL <- "https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv"
x <- getURL(URL)
## Or
## x <- getURL(URL, ssl.verifypeer = FALSE)
out <- read.csv(textConnection(x))
head(out[1:6])
# RT SERIALNO DIVISION PUMA REGION ST
# 1 H 186 8 700 4 16
# 2 H 306 8 700 4 16
# 3 H 395 8 100 4 16
# 4 H 506 8 700 4 16
# 5 H 835 8 800 4 16
# 6 H 989 8 700 4 16
dim(out)
# [1] 6496 188
download.file("https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06hid.csv",destfile="reviews.csv",method="libcurl")
这篇关于使用download.file()从HTTPS下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文