Jon*_*rne 5 zip curl r rstudio knitr
由于与网络安全系统的冲突,我可以将数据文件从互联网下载到网络中可以在R中使用的区域,这是通过R本身下载它.当我在RStudio中运行脚本时它工作正常.当我尝试编写脚本时,我会得到消息Unsupported URL或者我会得到
Error in file(file, "rt") : cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> read.csv ->
read.table -> file
Execution halted
Run Code Online (Sandbox Code Playgroud)
下面是在正常运行下但在编织过程中不起作用的代码.
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
download.file(url, "repdata-data-activity.zip")
unzip("repdata-data-activity.zip")
Run Code Online (Sandbox Code Playgroud)
如果文件不是一个zip我可以使用下载它RCurl,但是当我尝试的R坠毁,我也尝试过method = "curl", setInternet2(TRUE),并试图删除s从https,但他们都没有工作.
结果是我不能生产出问题的针织文件.我之前有一个非常类似的问题(CSV文件不是压缩的CSV文件,请参阅下面的链接)并尝试了建议但没有成功:从https网站获取数据时R产生"不支持的URL方案"错误
我使用的是Windows 7和RStudio
重复:这只是编织文档时的问题,而不是运行脚本时的问题.
问题是https和文件是二进制文件.通过将URL更改为http并将file.download设置为mode ="wb",问题得以解决,脚本可以成功编织.
最终代码块如下
url <- "http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
download.file(url, "repdata-data-activity.zip", mode="wb")
unzip("repdata-data-activity.zip")
Run Code Online (Sandbox Code Playgroud)