Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to download species models with ebirdst_download() #35

Closed
KWB4484 opened this issue May 3, 2022 · 6 comments
Closed

Comments

@KWB4484
Copy link

KWB4484 commented May 3, 2022

Hello. When I run ebirdst_download(species="Sharp-tailed Grouse") I get and error

"Error in ebirdst_download(species = "Sharp-tailed Grouse") :
Cannot access Status and Trends data URL. Ensure that you have a working internet connection and a valid API key for the Status and Trends data."

If I run this code below, which I took from the source code, I can download a species models. Am I messing something up or is this a bug? I suspect the former, but thought I'd ask. Thanks!

path = rappdirs::user_data_dir("ebirdst")
species <- get_species(species)
which_run <- which(ebirdst::ebirdst_runs$species_code == species)
run <- ebirdst::ebirdst_runs$run_name[which_run]
key<-Sys.getenv("EBIRDST_KEY")
api_url <- "https://st-download.ebird.org/v1/"
list_obj_url <- stringr::str_glue("{api_url}list-obj/{species}?key={key}")
files <-jsonlite::read_json(list_obj_url, simplifyVector = TRUE)
files <- data.frame(file = files)
files <- files[!stringr::str_detect(files$file, "\\.db$"), , drop = FALSE]
files$src_path <- stringr::str_glue("{api_url}fetch?objKey={files$file}",
                                    "&key={key}")
files$dest_path <- file.path(path, files$file)
files$exists <- file.exists(files$dest_path)
dirs <- unique(dirname(files$dest_path))
for (d in dirs) {
  dir.create(d, showWarnings = FALSE, recursive = TRUE)
}

old_timeout <- getOption("timeout")
options(timeout = max(3000, old_timeout))

for (i in seq_len(nrow(files))) {
  dl_response <- utils::download.file(files$src_path[i],
                                      files$dest_path[i],
                                      mode = "wb")
  if (dl_response != 0) {
    stop("Error downloading file: ", files$file[i])
  }
}
@mstrimas
Copy link
Collaborator

mstrimas commented May 3, 2022

Hi,

I just tested ebirdst_download(species="Sharp-tailed Grouse") and it's working fine for me. I'd suggest:

  1. Make sure you have a valid API key by visiting https://ebird.org/st/request. Update the key if needed, add it to your Renviron file with set_ebirdst_access_key("XXXXXXX", overwrite = TRUE), and restart R.
  2. Ensure you have the latest version of the package by installing from GitHub with: remotes::install_github("CornellLabofOrnithology/ebirdst")

If it's still not working, let me know and I'll try to get to the bottom of it.

@KWB4484
Copy link
Author

KWB4484 commented May 3, 2022

Thanks for the quick and helpful reply. I confirmed I have a valid key and Sys.getenv("EBIRDST_KEY") returns the correct key. I couldn't update the package though -- I got an error (see below). I appreciate the help but don't feel like you need to spend time on it. Like I said previously, I can at least download the models by running lines from the download function...so at least I'm not stuck anymore. I mostly just wanted to make sure it wasn't a bug. Seems like it's something that just doesn't work for me for whatever reason.

remotes::install_github("CornellLabofOrnithology/ebirdst")
Downloading GitHub repo CornellLabofOrnithology/ebirdst@HEAD
v  checking for file 'C:\Users\kbarnes\AppData\Local\Temp\1\RtmpG2AuLf\remotes1facac4c2\CornellLabofOrnithology-ebirdst-0a5d459/DESCRIPTION' ...
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
    ERROR
   copying to build directory failed
Error: Failed to install 'ebirdst' from GitHub:
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E>  ERROR
E> copying to build directory failed

@mstrimas
Copy link
Collaborator

mstrimas commented May 3, 2022

There has been some weirdness going on the past couple days with the eBird servers and it's possible this is related. It's worth waiting a couple days and checking again to see if it works.

Regarding the problem installing from GitHub, this sometimes happens on Windows because CornellLabofOrnithology/ebirdst is so long, you could try this instead:

remotes::install_github("ebird/ebirdst")

@KWB4484
Copy link
Author

KWB4484 commented May 3, 2022

Ok will do.

And thanks for the suggestion. Just as an FYI -- less warnings than last time, but looks like the sapsucker got rejected.

remotes::install_github("ebird/ebirdst")
Downloading GitHub repo ebird/ebirdst@HEAD
v  checking for file 'C:\Users\kbarnes\AppData\Local\Temp\1\RtmpG2AuLf\remotes1fac576f7735\ebird-ebirdst-0a5d459/DESCRIPTION' (439ms)
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     problem copying .\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_hr_2019_abundance-seasonal_breeding.tif to C:\Users\kbarnes\AppData\Local\Temp\1\Rtmpq4iuwx\Rbuild21204cc957f9\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_hr_2019_abundance-seasonal_breeding.tif: No such file or directory
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     problem copying .\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_lr_2019_abundance-seasonal_breeding.tif to C:\Users\kbarnes\AppData\Local\Temp\1\Rtmpq4iuwx\Rbuild21204cc957f9\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_lr_2019_abundance-seasonal_breeding.tif: No such file or directory
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     problem copying .\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_mr_2019_abundance-seasonal_breeding.tif to C:\Users\kbarnes\AppData\Local\Temp\1\Rtmpq4iuwx\Rbuild21204cc957f9\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_mr_2019_abundance-seasonal_breeding.tif: No such file or directory
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
   Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
     over-long path
    ERROR
   copying to build directory failed
Error: Failed to install 'ebirdst' from GitHub:
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   problem copying .\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_mr_2019_abundance-seasonal_breeding.tif to C:\Users\kbarnes\AppData\Local\Temp\1\Rtmpq4iuwx\Rbuild21204cc957f9\ebird-ebirdst-0a5d459\example-data\yebsap-ERD2019-STATUS-20200930-8d36d265-example\abundance_seasonal\yebsap-ERD2019-STATUS-20200930-8d36d265-example_mr_2019_abundance-seasonal_breeding.tif: No such file or directory
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long path
E> Warning in file.copy(pkgname, Tdir, recursive = TRUE, copy.date = TRUE) :
E>   over-long pat

@mstrimas
Copy link
Collaborator

mstrimas commented May 4, 2022

That's a pain, it's related to this issue r-lib/remotes#84

In the short term, they suggest using remotes::install_github("ebird/ebirdst", build = FALSE) may resolve the problem . For a proper solution, I clearly need to shorten the path names in the package, which I'll do in the next version. I guess for now you'll have to stick with the CRAN version of ebirdst. Sorry!

@mstrimas
Copy link
Collaborator

We've shortened the path names of the downloaded files and I've permanently moved the package to https://github.com/ebird/ebirdst, which should resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants