I have a snippet of code:
raw_prefix <- file.path("data", "raw")
fpa_prefix <- file.path(raw_prefix, "fpa-fod")
if(!dir.exists(fpa_prefix)){
dir.create(fpa_prefix)
}
fpa_gdb <- file.path(fpa_prefix, "RDS-2013-0009.4_GDB", "Data", "FPA_FOD_20170508.gdb")
if (!file.exists(fpa_gdb)) {
loc <- "https://www.fs.usda.gov/rds/fedora/objects/RDS:RDS-2013-0009.4/datastreams/RDS-2013-0009.4_GDB/content"
dest <- paste0(fpa_prefix, ".zip")
download.file(loc, dest)
unzip(dest, exdir = fpa_prefix)
unlink(dest)
assert_that(file.exists(fpa_gdb))
}
Which works great with most websites to download files on the fly in the name of reproducible workflows, but there is one dataset that I need which has an "href" and "target" file making it very difficult to download using download.file().
The file is found (also in above code) here:
https://www.fs.usda.gov/rds/archive/Product/RDS-2013-0009.4/
Towards the bottom of the page is a file called
RDS-2013-0009.4_GDB.zip
which is the file I am trying to download using the above script.
If you inspect this element you will find this structure, which returns the correct file! But how to translate into R code?
<a href="//www.fs.usda.gov/rds/fedora/objects/RDS:RDS-2013-0009.4/datastreams/RDS-2013-0009.4_GDB/content" target="_blank">RDS-2013-0009.4_GDB.zip</a>
If anyone has an idea on how to download this file I would GREATLY appreciate it!
Thanks!