ropensci / rnoaa

R interface to many NOAA data APIs
https://docs.ropensci.org/rnoaa
Other
328 stars 84 forks source link

`ghcnd_stations()` not finding file it expects (`ghcnd-stations.txt`) #349

Closed mpettis closed 4 years ago

mpettis commented 4 years ago

I just downloaded this package, and am trying to use it to find weather stations near me. Using the example from here, I cannot proceed past the first step. Please advise. Below is the reprex and session info.

Session:

library(rnoaa)
#> Warning: package 'rnoaa' was built under R version 3.6.3
station_data <- ghcnd_stations()
#> Error in curl::curl_fetch_disk(x$url$url, x$disk, handle = x$url$handle): Failed to open file C:\Users\IRINZN\AppData\Local\Cache\R\noaa_ghcnd\ghcnd-stations.txt.
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/Chicago             
#>  date     2020-05-13                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version   date       lib source        
#>  assertthat    0.2.1     2019-03-21 [1] CRAN (R 3.6.1)
#>  cli           2.0.2     2020-02-28 [1] CRAN (R 3.6.3)
#>  colorspace    1.4-1     2019-03-18 [1] CRAN (R 3.6.1)
#>  crayon        1.3.4     2017-09-16 [1] CRAN (R 3.6.1)
#>  crul          0.9.0     2019-11-06 [1] CRAN (R 3.6.1)
#>  curl          4.2       2019-09-24 [1] CRAN (R 3.6.1)
#>  digest        0.6.23    2019-11-23 [1] CRAN (R 3.6.1)
#>  dplyr         0.8.5     2020-03-07 [1] CRAN (R 3.6.3)
#>  ellipsis      0.3.0     2019-09-20 [1] CRAN (R 3.6.1)
#>  evaluate      0.14      2019-05-28 [1] CRAN (R 3.6.1)
#>  fansi         0.4.0     2018-10-05 [1] CRAN (R 3.6.1)
#>  ggplot2       3.2.1     2019-08-10 [1] CRAN (R 3.6.1)
#>  glue          1.3.1     2019-03-12 [1] CRAN (R 3.6.1)
#>  gridExtra     2.3       2017-09-09 [1] CRAN (R 3.6.1)
#>  gtable        0.3.0     2019-03-25 [1] CRAN (R 3.6.1)
#>  highr         0.8       2019-03-20 [1] CRAN (R 3.6.1)
#>  hoardr        0.5.2     2018-12-02 [1] CRAN (R 3.6.1)
#>  htmltools     0.4.0     2019-10-04 [1] CRAN (R 3.6.1)
#>  httpcode      0.2.0     2016-11-14 [1] CRAN (R 3.6.0)
#>  jsonlite      1.6       2018-12-07 [1] CRAN (R 3.6.1)
#>  knitr         1.26      2019-11-12 [1] CRAN (R 3.6.1)
#>  lazyeval      0.2.2     2019-03-15 [1] CRAN (R 3.6.1)
#>  lifecycle     0.2.0     2020-03-06 [1] CRAN (R 3.6.3)
#>  lubridate     1.7.4     2018-04-11 [1] CRAN (R 3.6.1)
#>  magrittr      1.5       2014-11-22 [1] CRAN (R 3.6.1)
#>  munsell       0.5.0     2018-06-12 [1] CRAN (R 3.6.1)
#>  pillar        1.4.3     2019-12-20 [1] CRAN (R 3.6.3)
#>  pkgconfig     2.0.3     2019-09-22 [1] CRAN (R 3.6.1)
#>  purrr         0.3.3     2019-10-18 [1] CRAN (R 3.6.1)
#>  R6            2.4.1     2019-11-12 [1] CRAN (R 3.6.1)
#>  rappdirs      0.3.1     2016-03-28 [1] CRAN (R 3.6.1)
#>  Rcpp          1.0.3     2019-11-08 [1] CRAN (R 3.6.1)
#>  rlang         0.4.5     2020-03-01 [1] CRAN (R 3.6.3)
#>  rmarkdown     1.18      2019-11-27 [1] CRAN (R 3.6.1)
#>  rnoaa       * 0.9.6     2020-04-07 [1] CRAN (R 3.6.3)
#>  scales        1.1.0     2019-11-18 [1] CRAN (R 3.6.1)
#>  sessioninfo   1.1.1     2018-11-05 [1] CRAN (R 3.6.1)
#>  stringi       1.4.3     2019-03-12 [1] CRAN (R 3.6.0)
#>  stringr       1.4.0     2019-02-10 [1] CRAN (R 3.6.1)
#>  tibble        3.0.1     2020-04-20 [1] CRAN (R 3.6.3)
#>  tidyr         1.0.0     2019-09-11 [1] CRAN (R 3.6.1)
#>  tidyselect    0.2.5     2018-10-11 [1] CRAN (R 3.6.1)
#>  triebeard     0.3.0     2016-08-04 [1] CRAN (R 3.6.1)
#>  urltools      1.7.3     2019-04-14 [1] CRAN (R 3.6.1)
#>  vctrs         0.2.4     2020-03-10 [1] CRAN (R 3.6.3)
#>  withr         2.1.2     2018-03-15 [1] CRAN (R 3.6.1)
#>  xfun          0.11      2019-11-12 [1] CRAN (R 3.6.1)
#>  XML           3.98-1.20 2019-06-06 [1] CRAN (R 3.6.0)
#>  xml2          1.2.2     2019-08-09 [1] CRAN (R 3.6.1)
#>  yaml          2.2.0     2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] C:/Users/IRINZN/Documents/R/R-3.6.1/library

Created on 2020-05-13 by the reprex package (v0.3.0)

sckott commented 4 years ago

thanks for the report @mpettis ! and for including your session info. i'll have a look

mpettis commented 4 years ago

Perhaps some helpful things I found on my machine:

    res <- GET_retry("ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt", 
            disk = ff, ...)

My suspicion is that when ghcnd_cache is defined in R/onload.R, assigning it here , that directory path is expected to be created upon instantiation. But it is not.

mpettis commented 4 years ago

I suspect a call to ghcnd_cache$mkdir() is required prior to the GET_retry() call. I'm not sure if it should go in just prior, or somewhere further up the call stack. I could do a fork and pull request if that helps you out by placing that call just prior to GET_retry()...

sckott commented 4 years ago

thanks very much - i suspect you're right, having a look at the PR