Due to clash with the network security system the only way I cand download a data file from the internet to an area in the network where it can be used in R it is by downloading it through R itself. When I run the script in RStudio it works fine. When I try to knit the script I will get either the message Unsupported URL
or I will get
Error in file(file, "rt") : cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> read.csv ->
read.table -> file
Execution halted
below is the code that works under normal running but not during the knitting process.
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
download.file(url, "repdata-data-activity.zip")
unzip("repdata-data-activity.zip")
If the file wasn't a zip I could download it using RCurl
, but when I tried that R crashed, I have also tried method = "curl", setInternet2(TRUE)
, and trying to remove the s
from https
but none of them have worked.
The result is that I cannot produce a knitted document which is a problem. I have previous on a very similar problem ( a CSV file not a zipped CSV file, see link below) and have tried the advice but without success: R produces "unsupported URL scheme" error when getting data from https sites
I am using Windows 7 and RStudio
To repeat: this is ONLY a problem WHEN KNITTING the document, not when running the script.
The problem was both the https and that the file is a binary. By changing the URL to http and setting file.download to mode="wb" the problem was resolved and the script could be knitted successfully.
Final code chunk is as follows
url <- "http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2Factivity.zip"
download.file(url, "repdata-data-activity.zip", mode="wb")
unzip("repdata-data-activity.zip")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With