Reputation: 1137
I am trying to download a file in R 3.0.1 (Windows 7):
fileUrl <- "https://data.baltimorecity.gov/api/views/dz54-2aru/rows.csv?accessType=DOWNLOAD"
download.file(fileUrl, destfile="./data/cameras.csv", method="curl")
I checked both the url and my internet connection and they seem to be working just fine. However, I get this message:
Warning message:
In download.file(fileUrl, destfile = "./data/cameras.csv", method = "curl") :
download had nonzero exit status
Can't find any help online, anybody knows how to fix this?
Upvotes: 14
Views: 34168
Reputation: 41
file<-'http://data.baltimorecity.gov/api/views/dz54-2aru/rows.csv?accessType=DOWNLOAD'
download.file(file, destfile="cameras.csv")
Upvotes: 3
Reputation: 327
I have gotten the same error a sec ago the exact same task at hand. For me the issue was, that I was not in the right working directory.
The solution: in the right bottom corner window (compare picture), click "More" and than "Set as working directory".
Try the download again! For me it worked fine.
Upvotes: 0
Reputation: 53
if you write method="libcurl" then it will work for both http or https url
Upvotes: 0
Reputation: 641
It just happened to me. In order to get it working, you just need to get rid of the 's
' in 'https
' and also don't specify 'method = curl
'. I'm just beginning so got no idea how it works, but hey it does the job.
Upvotes: 1
Reputation: 11
I found this works after by omitting the ssl in https ie
NatGas <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2FDATA.gov_NGAP.xlsx"
and then set the method to "auto"
download.file(NatGas, destfile = "./TidyData/NatGas.xlsx",method = "auto", mode ="wb")
Upvotes: 1
Reputation: 21
I found that I had to actually download curl from the haxx site and then add its location to the path in the system environment variables. After that the
download.file(fileURL, destfile = "data/cameras.csv", method = "curl")
command worked fine. This was on a Windows 7, 64bit machine.
Upvotes: 0
Reputation: 21
@dickoa: Given the fact that you get "TRUE" when you do:
file.exists("./data")
I suppose you have written initially:
if (!file.exists("data")) { file.create("data") }
before you perform the code you shared to download the csv. However, this creates a file "data", not a directory. So the following should be written in your R script before your code:
if (!file.exists("data")) { dir.create("data") }
After this, I believe your code should work fine. Hope this helps.
Upvotes: 2
Reputation: 23
fileUrl1 <- "https://... xyz.csv"
download.file(fileUrl1, destfile="./data/xyz.csv", method="curl")
Use the following (http instead of https in the 1st line and in 2nd line remove mehod="curl")
fileUrl1 <- "http://... xyz.csv"
download.file(fileUrl1, destfile="./data/xyz.csv")
try this ,you can download the csv file
Upvotes: 2
Reputation: 31
Use setInternet2 before you download. it worked for me.
setInternet2(use=T)
file <- "URL"
download.file(file,destfile= "./data/cameras.csv")
Upvotes: 3
Reputation: 1904
When you call download.file()
, it doesn't create the directory for you.
Instead you need to have a valid directory already created for it to create the file.
My guess is that you haven't created the folder called data
yet.
Hope this helps.
Upvotes: 1
Reputation: 1
I tried two methods for downloading the same file:
Download the package "downloader" using install.packages("downloader")
and then load the package using require(downloader)
command. After this, use the command: download(fileurl,"./data/camera.csv",mode="wb")
The other method is:
file<-'http://data.baltimorecity.gov/api/views/dz54-2aru/rows.csv?accessType=DOWNLOAD' read.csv(file)
and save the data.frame
file using write.csv
method to save the file.
Upvotes: 0
Reputation: 1
Try changing the line from "method=curl" to "method=internal"
If you want to use the curl method, you need to install the curl library onto your computer, at http://curl.haxx.se/
Upvotes: 0
Reputation: 18323
The answer by @dickoa probably works, but I think the major issue is that you are using https
unnecessarily. I think this works:
# Note the http instead of https
file<-'http://data.baltimorecity.gov/api/views/dz54-2aru/rows.csv?accessType=DOWNLOAD'
read.csv(file)
Upvotes: 9
Reputation: 18437
Still don't understand why removing method = "curl"
don't solve the problem.
Another solution is install the downloader
package which wrap download.file
and make the download process easier and cross-platform (one function with same paramters for all OS)
install.packages("downloader")
fileUrl <- "https://data.baltimorecity.gov/api/views/dz54-2aru
/rows.csv?accessType=DOWNLOAD"
require(downloader)
download(fileUrl, "data/cameras.csv", mode = "wb")
Hope that it will work this time
Upvotes: 17