I would like to download a file directly into my working directory
I can do this to a temp directory:
download.file("http://www.abc.com/abc.zip",temp)
but what do I have to replace temp with to get it to download to the working directory?
Downloading a file to a specific directory When downloading a file, Wget stores it in the current directory by default. You can change that by using the -P option to specify the name of the directory where you want to save the file.
If your url is in a variable, you can use basename
to get the "filename" part out of it:
u <- "http://www.abc.com/abc.zip"
basename(u) # "abc.zip"
# downloads to current directory:
download.file(u, basename(u))
# downloads to subdirectory "foo":
download.file(u, file.path("foo", basename(u)))
The second argument of download.file()
is destfile
and it must be specified. I don't have a Windows machine to test this on, but both of these work on my linux box and I can't see why at least the second won't work on Windows too:
download.file("http://www.abc.com/abc.zip", "./abc.zip")
download.file("http://www.abc.com/abc.zip", "abc.zip")
The second of those indicates that if you just give a filename, the file will be download to the current working directory and saved under the stated name.
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