ropensci / rnoaa

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

Error running `ghcnd_search` with CRAN version of `rnoaa` but not GitHub version #173

Closed geanders closed 7 years ago

geanders commented 7 years ago

When running examples from the help file for ghcnd_search with the version of rnoaa on GitHub (ropensci/rnoaa), it's working fine:

devtools::install_github("ropensci/rnoaa")
devtools::session_info()$packages %>% filter(package == "rnoaa")

# package *    version       date                          source
#1   rnoaa * 0.6.4.9000 2016-10-21 Github (ropensci/rnoaa@e5f8bfe)

library(rnoaa)
ghcnd_search("AGE00147704", var = "PRCP")

# $prcp
# # A tibble: 9,803 × 6
# id  prcp       date mflag qflag sflag
# <chr> <int>     <date> <lgl> <chr> <chr>
#1  AGE00147704    NA 1909-11-01    NA            
#2  AGE00147704    24 1909-12-01    NA           E
#3  AGE00147704    82 1910-01-01    NA           E
#4  AGE00147704     0 1910-02-01    NA           E
#5  AGE00147704    18 1910-03-01    NA           E
#6  AGE00147704     0 1910-04-01    NA           E
#7  AGE00147704   224 1910-05-01    NA           E
#8  AGE00147704     0 1910-06-01    NA           E
#9  AGE00147704     0 1910-07-01    NA           E
#10 AGE00147704     0 1910-08-01    NA           E
# # ... with 9,793 more rows

However, when I try with the current version on CRAN, I'm getting an error running the same thing:

install.packages("rnoaa")
devtools::session_info()$packages %>% filter(package == "rnoaa")
# package * version       date         source
#1   rnoaa *   0.6.4 2016-10-07 CRAN (R 3.3.0)

library(rnoaa)
ghcnd_search("AGE00147704", var = "PRCP")
# Error in file(file, ifelse(append, "a", "w")) : 
#   cannot open the connection
# In addition: Warning message:
#   In file(file, ifelse(append, "a", "w")) :
#   cannot open file '/Users/urbanek/Library/Caches/rnoaa/ghcnd/AGE00147704.dly': 
#   No such file or directory

From the commit history, it doesn't look like there have been any commits to the GitHub version since the latest version was released to CRAN, so I'm confused about why the CRAN version isn't working while the GitHub version is. It looks like something to do with the caching, based on the error message, but I'm having a hard time figuring out what's going wrong with the CRAN version. Any tips?

For the record, here's the rest of my session_info while running this:

Session info ----------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.0.40)            
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Denver              
 date     2016-10-21                  

Packages --------------------------------------------------------------------------
 package    * version    date       source                         
 assertthat   0.1        2013-12-06 CRAN (R 3.3.0)                 
 colorspace   1.2-6      2015-03-11 CRAN (R 3.3.0)                 
 curl         2.1        2016-09-22 CRAN (R 3.3.0)                 
 DBI          0.5        2016-08-11 CRAN (R 3.3.0)                 
 devtools   * 1.12.0     2016-06-24 CRAN (R 3.3.0)                 
 digest       0.6.10     2016-08-02 CRAN (R 3.3.0)                 
 dplyr      * 0.5.0      2016-06-24 CRAN (R 3.3.0)                 
 ggplot2      2.1.0      2016-03-01 CRAN (R 3.3.0)                 
 git2r        0.15.0     2016-05-11 CRAN (R 3.3.0)                 
 gridExtra    2.2.1      2016-02-29 CRAN (R 3.3.0)                 
 gtable       0.2.0      2016-02-26 CRAN (R 3.3.0)                 
 httr         1.2.1      2016-07-03 cran (@1.2.1)                  
 jsonlite     1.1        2016-09-14 cran (@1.1)                    
 knitr        1.14       2016-08-13 CRAN (R 3.3.0)                 
 lazyeval     0.2.0      2016-06-12 cran (@0.2.0)                  
 lubridate    1.6.0      2016-09-13 CRAN (R 3.3.0)                 
 magrittr     1.5        2014-11-22 CRAN (R 3.3.0)                 
 memoise      1.0.0      2016-01-29 CRAN (R 3.3.0)                 
 mime         0.5        2016-07-07 cran (@0.5)                    
 munsell      0.4.3      2016-02-13 CRAN (R 3.3.0)                 
 plyr         1.8.4      2016-06-08 CRAN (R 3.3.0)                 
 R6           2.2.0      2016-10-05 CRAN (R 3.3.0)                 
 rappdirs     0.3.1      2016-03-28 CRAN (R 3.3.0)                 
 Rcpp         0.12.7     2016-09-05 cran (@0.12.7)                 
 rnoaa      * 0.6.4.9000 2016-10-21 Github (ropensci/rnoaa@e5f8bfe)
 rstudioapi   0.6        2016-06-27 CRAN (R 3.3.0)                 
 scales       0.4.0      2016-02-26 CRAN (R 3.3.0)                 
 stringi      1.1.1      2016-05-27 CRAN (R 3.3.0)                 
 stringr      1.1.0      2016-08-19 cran (@1.1.0)                  
 tibble       1.2        2016-08-26 cran (@1.2)                    
 tidyr        0.6.0      2016-08-12 cran (@0.6.0)                  
 withr        1.0.2      2016-06-20 CRAN (R 3.3.0)                 
 XML          3.98-1.4   2016-03-01 CRAN (R 3.3.0)                 
 xml2         1.0.0      2016-06-24 CRAN (R 3.3.0)      
sckott commented 7 years ago

somehow urbanek is getting injected into the user cache directory - happened on my machine as well. looking into how that can happen

sckott commented 7 years ago

it only happens when I installed the binary version from CRAN, works fine when installing source version from CRAN

sckott commented 7 years ago

@kevinushey so this is really weird.

On installation of a binary version from cran of this package, somehow the rappdirs::user_cache_dir call injects urbanek as the user instead of whoever the user is (e.g., sacmac for me)

This doesn't happen when installing source from cran, or installing from local git repo, etc.

I'm guessing this could be a problem in rappdirs:::file_path, which has

<r> file_path
function(...) {
  normalizePath(do.call("file.path", as.list(c(...))), mustWork = FALSE)
}

so a potential problem in normalizePath

maybe i'm missing something obvious

kevinushey commented 7 years ago

I see something similar on a Windows install:

> ghcnd_search("AGE00147704", var = "PRCP")
Warning in file(file, ifelse(append, "a", "w")) :
  cannot open file 'C:\Users\CRAN\AppData\Local\rnoaa\rnoaa\Cache/ghcnd/AGE00147704.dly': No such file or directory
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection

Perhaps the rnoaa package is calling an rappdirs function when the package is built, rather than at runtime / in a .onLoad handler?

kevinushey commented 7 years ago

The issue is here:

https://github.com/ropensci/rnoaa/blob/e5f8bfef6e0b850c65ca7025341e1bc832f82f44/R/aaa.r#L1-L3

That code in aaa.R gets run on package build, so the username used when the package is built is what gets used by the package. Moving that code into the .onLoad handler should help.

sckott commented 7 years ago

ah yeah, makes sense, thanks @kevinushey !

sckott commented 7 years ago

@geanders i'll get a new version on cran by tomorrow

sckott commented 7 years ago

this is sorted now, pushing to cran today

geanders commented 7 years ago

Thanks so much!


From: Scott Chamberlain notifications@github.com Sent: Friday, October 21, 2016 8:12:47 PM To: ropensci/rnoaa Cc: Anderson,Brooke; Mention Subject: Re: [ropensci/rnoaa] Error running ghcnd_search with CRAN version of rnoaa but not GitHub version (#173)

@geandershttps://github.com/geanders i'll get a new version on cran by tomorrow

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ropensci/rnoaa/issues/173#issuecomment-255501297, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFVFiN-7l1IkzfnGaqthBY2NmYLs1OESks5q2XEfgaJpZM4Kdq-G.