SCalabre
SCalabre

Reputation: 103

Permission Denied Error when downloading a file

I am trying to download an excel zip file into a R Project folder that I have started. I'm new to R so I'm a little puzzled at the error message that I'm receiving.

The file is an excel file and so first I created a variable for the file:

excel2file="http://op.nsf.data/dataFiles/Housing2013EXCEL.zip"

Then I used the coding:

download.file(excel2file, destfile= "~/Home/Documents/Data")

I receive this error message:

Error in download.file(excel2file, destfile = "~/Home/Documents/Data") : 
  cannot open destfile '~/Home/Documents/Data', reason 'Permission denied'

I tried looking at other examples of permission denied and I think it may be my destination file but I am not sure why or the steps to trouble shoot it.

Upvotes: 10

Views: 23503

Answers (5)

derelict
derelict

Reputation: 3906

You can also use basename with paste, which would be useful if downloading a bunch of files.

For example:

(excel2file="http://op.nsf.data/dataFiles/Housing2013EXCEL.zip")
(file_name <- basename(excel2file))

download.file(excel2file, destfile= paste("~/Home/Documents/Data",file_name, sep="/"))

Upvotes: 0

Renzo
Renzo

Reputation: 1

You could use the package readr and its function read_csv. It allows you to download the file, but it has to be a downloaded files such as a CSV file, something like this worked for me

library(readr)

newz <- read_csv("https://www.stats.govt.nz/assets/Uploads/Annual-enterprise-survey/Annual-enterprise-survey-2020-financial-year-provisional/Download-data/annual-enterprise-survey-2020-financial-year-provisional-csv.csv")

View(newz)

about the "Permission Denied" I still doesn`t solved that problem

Upvotes: 0

Nikhil Sharma
Nikhil Sharma

Reputation: 1

add a name in destfile like /downloadedfile.csv"

Upvotes: -3

Evan Friedland
Evan Friedland

Reputation: 3184

Make sure you don't have the file already open in the destfile, as the Permission denied error also comes from being unable to overwrite an open file.

This tripped me up for a while.

Upvotes: 1

Thomas
Thomas

Reputation: 44555

destfile should be a filename, not a directory. For example:

download.file(excel2file, destfile= "~/Home/Documents/Data/Housing2013EXCEL.zip")

Also, that URL doesn't seem to be valid, but that's a different (non-R) problem.

Upvotes: 21

Related Questions