kunstler / laselva

Fetch Forest Inventory data from many countries
https://docs.ropensci.org/laselva
Other
9 stars 4 forks source link

`all` argument broken in fia_fetch #5

Closed taddallas closed 8 years ago

taddallas commented 8 years ago

Playing around with the package, and fia_fetch returns

Error in handle_errors(res, fpath) : Not Found (HTTP 404).

from fia_fetch("all", "subplot_regen") taken from fia_fetch documentation.

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] laselva_0.0.2.9500

loaded via a namespace (and not attached):
 [1] readr_1.0.0     httr_1.2.1      assertthat_0.1  R6_2.1.2       
 [5] tools_3.3.1     withr_1.0.1     tibble_1.1      rappdirs_0.3.1 
 [9] curl_1.2        Rcpp_0.12.6     memoise_1.0.0   git2r_0.15.0   
[13] digest_0.6.10   devtools_1.11.1
taddallas commented 8 years ago

Easy fix, though it could be prettier, I bet (pasted below).

@sckott: I'd like to help out with this effort if I can. I have a cloned copy of the repo, but don't have permissions to push any of my changes. I have a branch named tad currently on my local machine.

fia_fetch <- function(state, what = "tree", overwrite = FALSE, ...) {
  stopifnot(inherits(what, "character"))
  stopifnot(length(what) >= 1)
  if(state=='all'){
    urls <- file.path(fia_base(), "CSV", paste0(what, ".zip"))
  }else{
    urls <- unlist(lapply(state, function(x) {
      file.path(fia_base(), "CSV", paste0(x, "_", what, ".zip"))
    }))
  }
  nms <- gsub("\\.zip", "", basename(urls))
  setNames(lapply(urls, function(z) {
    xx <- fia_cache_GET(z, overwrite, ...)
    suppressMessages(readr::read_csv(un_zip(xx)))
  }), nms)
}
sckott commented 8 years ago

Right, I didn't yet implement the all option for that parameter.

Thanks for helping. Can you fork to your account, create that new branch, add your changes, then push back up to your account, then send pull request here

sckott commented 8 years ago

fix via #6