Reputation: 407
if(!file.exists("./data/c3w4")){dir.create("./data/c3w4")}
url341 <- "https://d396qusza40orc.cloudfront.net/getdata%2Fprojectfiles%2FUCI%20HAR%20Dataset.zip"
download.file(url341, destfile = "./data/c3w4/pr341.zip")
I sure i used this set of command to download the file initially, but now that I am trying to reproduce code it is give the the error Error in download.file(url341, destfile = "./data/c3w4/") :
cannot open destfile './data/c3w4/', reason 'No such file or directory'
This is some relevant output from my console: I did delete the "pr341.zip" file i downloaded the first time.
> getwd()
[1] "C:/Users/avtarsingh/Downloads"
> list.dirs()
[1] "."
[2] "./data"
[3] "./data/c3w4"
[4] "./data/c3w4/UCI HAR Dataset"
[5] "./data/c3w4/UCI HAR Dataset/test"
[6] "./data/c3w4/UCI HAR Dataset/test/Inertial Signals"
[7] "./data/c3w4/UCI HAR Dataset/train"
[8] "./data/c3w4/UCI HAR Dataset/train/Inertial Signals"
[9] "./new"
> list.files("./data/c3w4")
[1] "project.Rmd" "UCI HAR Dataset"
*(added with edit) Just noticed that if I copy and paste the code from R markdown to the console, it works. Why?
Upvotes: 0
Views: 161
Reputation: 6755
My experience with rmarkdown is that you really need to understand that the working directory is not the same as the working directory in the console and you can't make the assumptions that "." in a path implies. If you getwd()
and use paste()
to create the full file path that will usually work, but you must make sure you have created any folders that you need in whatever location (which may not be obvious) is being used as the working directory. Of course you can test this to find out and then construct things directly, meaning do a test document with getwd() to find out what the actual knitr working directory is, then build the file path from there.
Often for me I end up with something like
paste0("~","downloads/","filname")
Upvotes: 3