JerryN
JerryN

Reputation: 2506

r what doesn't curl_download like about a filename

I want to download some files (NetCDF although I don't think that matters) from a website and write them to a specified data directory on my hard drive. Some code that illustrates my problems follows

library(curl)

baseURL <- "http://gsweb1vh2.umd.edu/LUH2/LUH2_v2f/"

fileChoice <- "IMAGE_SSP1_RCP19/multiple-states_input4MIPs_landState_ScenarioMIP_UofMD-IMAGE-ssp119-2-1-f_gn_2015-2100.nc"
destDir <- paste0(getwd(), "/data-raw/")
url <- paste0(baseURL, fileChoice)
destfile <- paste0(destDir, "test.nc")
curl_download(url, destfile) # this one works
destfile <- paste0(destDir, fileChoice)
curl_download(url, destfile) #this one fails

The error message is

Error in curl_download(url, destfile) : 
  Failed to open file /Users/gcn/Documents/workspace/landuse/data-raw/IMAGE_SSP1_RCP19/multiple-states_input4MIPs_landState_ScenarioMIP_UofMD-IMAGE-ssp119-2-1-f_gn_2015-2100.nc.curltmp.

It turns out the curl_download internally adds .curltmp to destfile and then removes it. I can't figure out what is writing

Upvotes: 2

Views: 784

Answers (1)

JerryN
JerryN

Reputation: 2506

It turns out that the problem is the fileChoice variable includes a new directory; IMAGE_SSP1_RCP19. Once I created the directory the process worked fine. I'm posting this because someone else might make the same mistake I did.

Upvotes: 2

Related Questions