1

I have this code right here

# Load package heavyRain and RCurl
library(heavyRain)
library(RCurl)

 #Assigning url and destfile
url <- "ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CHIRPS-2.0/"

destfile <- "New Chirps Data.R"

 #Download CHIRPS
Download.chirps <- getCHIRPS(
          region = "Europe",
           format = "netcdf",
          tres = "monthly",
           sres = 0.05,
          begin = as.Date("1981-01-01"), end = as.Date("2020-11-30"),
           download.file(url, destfile)
           
       )

I get the following error message which I'm a bit of trouble getting rid off.

trying URL 'ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CHIRPS-2.0/'
Error in download.file(url, destfile) : 
  cannot open URL 'ftp://chg-ftpout.geog.ucsb.edu/pub/org/chg/products/CHIRPS-2.0/'
In addition: Warning message:
In download.file(url, destfile) :
  InternetOpenUrl failed: 'The server name or address could not be resolved
'

How do I solve this problem?

5
  • Where did you get that URL from? It points to an invalid IP name.
    – Spacedman
    Commented Dec 22, 2020 at 14:02
  • A friend sent to me he said that he got it from the package "heavyRain"
    – codeload
    Commented Dec 22, 2020 at 14:56
  • The heavyRain package doesn't seem to be on CRAN so where does that even come from?
    – Spacedman
    Commented Dec 22, 2020 at 16:41
  • Is this it? github.com/environmentalinformatics-marburg/heavyRain
    – Spacedman
    Commented Dec 22, 2020 at 21:28
  • Yeah...that one
    – codeload
    Commented Dec 23, 2020 at 5:04

4 Answers 4

2

Having found the package, downloaded it, tried the HTTPS url and found that failed, I've debugged the code and discovered that it relies on an FTP service in order to download the list of files on the server. Via the HTTPS url an HTML string is returned and so the code falls over trying to get the list of files.

In short, the code needs rewriting. I've filed an issue for you at that github repository:

https://github.com/environmentalinformatics-marburg/heavyRain/issues/7

1
1

I encountered the same problem, but a solution that worked for me was typing the following:

trace(heavyRain:::serverPath, edit = T)

At the place where you find the outdated link, you replace it with ftp://ftp.chc.ucsb.edu/pub/org/chc/products/CHIRPS- This worked for me, I hope it works for you too. I am not a genius in R, but for as well as I understood, this trace function only changes the function for the R session you are working in...

1

I think that your best bet is the chirps package, on CRAN and GitHub (https://github.com/ropensci/chirps). It turns our that the Climate Hazards Group InfraRed Precipitation with Station Data group has an api that this package leverages. Using curl or RCurl, it would be fairly simple to list all the links in the directory and loop through a download but, I have no idea on the maintenance of the repository containing the tiff/bil data. I would reccomend using the API because it is assured that this contains the latest version of the data.

1
  • Okay, thanks a lot. Let me work on it
    – codeload
    Commented Dec 23, 2020 at 5:10
1

Here an example using the R package chirps. You can also change the data provider using the argument server. ClimateSERV takes the data from SERVIR Global, which I recommend when you have few data points. CHC takes the data directly from CHIRPS servers and is recommended when you deal with multiple data points and dates.

library("chirps")

lonlat <- data.frame(lon = -67.5, lat = -24.5)
dates <- c("1981-01-02", "2020-12-31")
data <- get_chirps(lonlat, dates, server = "ClimateSERV")

data

I recommend this one when you deal with multiple points (>500) and dates at the same time

lonlat <- data.frame(lon = -67.5, lat = -24.5)
dates <- c("1981-01-02", "1981-01-04")
data <- get_chirps(lonlat, dates, server = "CHC")

data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.