ropensci / weathercan

R package for downloading weather data from Environment and Climate Change Canada
https://docs.ropensci.org/weathercan
GNU General Public License v3.0
102 stars 29 forks source link

Error in strptime(xx, f, tz = tz) : invalid 'tz' value #70

Closed essicolo closed 5 years ago

essicolo commented 5 years ago

Expected Behavior

Fetching weather using weather_dl().

Current Behavior

> mont_bellevue <- weather_dl(station_ids = 5397,
+                             start = "2019-02-01",
+                             end = "2019-02-07",
+                             interval = "hour",
+                             verbose = TRUE)
Getting station: 5397
Formatting station data: 5397
Error in strptime(xx, f, tz = tz) : invalid 'tz' value

Steps to Reproduce (for bugs)

I'm doing a lot computations before getting the error. I tried several things and could not create a reproducible example.

Possible Solution

Imcompatibility with another package?

Context

I'm trying to build a gitbook with several chapters. A chapter including weathercan can be run alone, but the whole book (i.e. compiling previous chapters beforehand) throws the error.

Your Environment

- Session info --------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.3 (2019-03-11)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  French_France.1252          
 ctype    French_France.1252          
 tz       America/New_York            
 date     2019-03-15                  

- Packages ------------------------------------------------------------------------------------------------
 ! package        * version    date       lib source                                      
   agridat        * 1.16       2018-07-06 [1] CRAN (R 3.5.1)                              
   assertthat       0.2.0      2017-04-11 [1] CRAN (R 3.5.1)                              
   backports        1.1.3      2018-12-14 [1] CRAN (R 3.5.2)                              
   base64enc        0.1-3      2015-07-28 [1] CRAN (R 3.5.0)                              
   bayesm         * 3.1-1      2018-12-21 [1] CRAN (R 3.5.2)                              
   bookdown         0.9        2018-12-21 [1] CRAN (R 3.5.2)                              
   boot             1.3-20     2017-08-06 [2] CRAN (R 3.5.3)                              
   broom            0.5.1      2018-12-05 [1] CRAN (R 3.5.2)                              
   callr            3.1.1      2018-12-21 [1] CRAN (R 3.5.2)                              
   cellranger       1.1.0      2016-07-27 [1] CRAN (R 3.5.1)                              
   cli              1.0.1      2018-09-25 [1] CRAN (R 3.5.1)                              
   cluster          2.0.7-1    2018-04-13 [2] CRAN (R 3.5.3)                              
   coda             0.19-2     2018-10-08 [1] CRAN (R 3.5.1)                              
   codetools        0.2-16     2018-12-24 [2] CRAN (R 3.5.3)                              
   colorspace       1.4-0      2019-01-13 [1] CRAN (R 3.5.2)                              
   compositions   * 1.40-2     2018-06-14 [1] CRAN (R 3.5.2)                              
   cranlogs         2.1.0      2015-12-07 [1] CRAN (R 3.5.2)                              
   crayon           1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                              
   curl             3.3        2019-01-10 [1] CRAN (R 3.5.2)                              
   data.table       1.12.0     2019-01-13 [1] CRAN (R 3.5.2)                              
   DEoptimR         1.0-8      2016-11-19 [1] CRAN (R 3.5.0)                              
   desc             1.2.0      2018-05-01 [1] CRAN (R 3.5.1)                              
   devtools         2.0.1      2018-10-26 [1] CRAN (R 3.5.1)                              
   digest           0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                              
   dplyr          * 0.8.0.1    2019-02-15 [1] CRAN (R 3.5.3)                              
   ellipsis         0.1.0      2019-02-19 [1] CRAN (R 3.5.3)                              
   energy         * 1.7-5      2018-08-11 [1] CRAN (R 3.5.1)                              
   evaluate         0.13       2019-02-12 [1] CRAN (R 3.5.2)                              
   fansi            0.4.0      2018-10-05 [1] CRAN (R 3.5.1)                              
   forcats        * 0.4.0      2019-02-17 [1] CRAN (R 3.5.3)                              
   formattable      0.2.0.1    2016-08-05 [1] CRAN (R 3.5.2)                              
   fs               1.2.6      2018-08-23 [1] CRAN (R 3.5.1)                              
   future           1.12.0     2019-03-08 [1] CRAN (R 3.5.3)                              
   generics         0.0.2      2018-11-29 [1] CRAN (R 3.5.1)                              
   ggplot2        * 3.1.0      2018-10-25 [1] CRAN (R 3.5.1)                              
   globals          0.12.4     2018-10-11 [1] CRAN (R 3.5.2)                              
   glue             1.3.1      2019-03-12 [1] CRAN (R 3.5.3)                              
   greta          * 0.3.0      2018-10-30 [1] CRAN (R 3.5.3)                              
   gtable           0.2.0      2016-02-26 [1] CRAN (R 3.5.1)                              
   haven            2.1.0      2019-02-19 [1] CRAN (R 3.5.3)                              
   hms              0.4.2      2018-03-10 [1] CRAN (R 3.5.1)                              
   htmltools        0.3.6      2017-04-28 [1] CRAN (R 3.5.1)                              
   htmlwidgets      1.3        2018-09-30 [1] CRAN (R 3.5.1)                              
   httr             1.4.0      2018-12-11 [1] CRAN (R 3.5.1)                              
   janitor          1.1.1      2018-07-31 [1] CRAN (R 3.5.2)                              
   jsonlite         1.6        2018-12-07 [1] CRAN (R 3.5.1)                              
   knitr            1.22       2019-03-08 [1] CRAN (R 3.5.3)                              
   labeling         0.3        2014-08-23 [1] CRAN (R 3.5.0)                              
   lattice        * 0.20-38    2018-11-04 [1] CRAN (R 3.5.1)                              
   lazyeval         0.2.1      2017-10-29 [1] CRAN (R 3.5.1)                              
   listenv          0.7.0      2018-01-21 [1] CRAN (R 3.5.3)                              
   lubridate      * 1.7.4      2018-04-11 [1] CRAN (R 3.5.1)                              
   magrittr         1.5        2014-11-22 [1] CRAN (R 3.5.1)                              
   MASS             7.3-51.1   2018-11-01 [1] CRAN (R 3.5.1)                              
 R Matrix           1.2-15     <NA>       [2] <NA>                                        
   memoise          1.1.0      2017-04-21 [1] CRAN (R 3.5.1)                              
   mgcv             1.8-27     2019-02-06 [1] CRAN (R 3.5.2)                              
   modelr           0.1.4      2019-02-18 [1] CRAN (R 3.5.3)                              
   munsell          0.5.0      2018-06-12 [1] CRAN (R 3.5.1)                              
   nlme           * 3.1-137    2018-04-07 [2] CRAN (R 3.5.3)                              
   packagemetrics * 0.0.1.9001 2019-03-15 [1] Github (ropenscilabs/packagemetrics@00846df)
   packrat          0.5.0      2018-11-14 [1] CRAN (R 3.5.1)                              
   permute        * 0.9-5      2019-03-12 [1] CRAN (R 3.5.3)                              
   pillar           1.3.1      2018-12-15 [1] CRAN (R 3.5.2)                              
   pkgbuild         1.0.2      2018-10-16 [1] CRAN (R 3.5.1)                              
   pkgconfig        2.0.2      2018-08-16 [1] CRAN (R 3.5.1)                              
   pkgload          1.0.2      2018-10-29 [1] CRAN (R 3.5.1)                              
   plotly         * 4.8.0      2018-07-20 [1] CRAN (R 3.5.1)                              
   pls            * 2.7-0      2018-08-21 [1] CRAN (R 3.5.1)                              
   plyr             1.8.4      2016-06-08 [1] CRAN (R 3.5.1)                              
   prettyunits      1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                              
   processx         3.3.0      2019-03-10 [1] CRAN (R 3.5.3)                              
   progress         1.2.0      2018-06-14 [1] CRAN (R 3.5.1)                              
   ps               1.3.0      2018-12-21 [1] CRAN (R 3.5.2)                              
   purrr          * 0.3.1      2019-03-03 [1] CRAN (R 3.5.3)                              
   R6               2.4.0      2019-02-14 [1] CRAN (R 3.5.1)                              
   Rcpp             1.0.0      2018-11-07 [1] CRAN (R 3.5.1)                              
   readr          * 1.3.1      2018-12-21 [1] CRAN (R 3.5.2)                              
   readxl           1.3.1      2019-03-13 [1] CRAN (R 3.5.3)                              
   remotes          2.0.2      2018-10-30 [1] CRAN (R 3.5.1)                              
   reshape2         1.4.3      2017-12-11 [1] CRAN (R 3.5.1)                              
   reticulate       1.11.1     2019-03-06 [1] CRAN (R 3.5.3)                              
   rlang            0.3.1      2019-01-08 [1] CRAN (R 3.5.2)                              
   rmarkdown        1.12       2019-03-14 [1] CRAN (R 3.5.2)                              
   robustbase     * 0.93-3     2018-09-21 [1] CRAN (R 3.5.1)                              
   rprojroot        1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                              
   rsconnect        0.8.13     2019-01-10 [1] CRAN (R 3.5.2)                              
   rstudioapi       0.9.0      2019-01-09 [1] CRAN (R 3.5.2)                              
   rvest            0.3.2      2016-06-17 [1] CRAN (R 3.5.1)                              
   scales           1.0.0      2018-08-09 [1] CRAN (R 3.5.1)                              
   selectr          0.4-1      2018-04-06 [1] CRAN (R 3.5.1)                              
   sessioninfo      1.1.1      2018-11-05 [1] CRAN (R 3.5.1)                              
   skimr            1.0.5      2019-02-25 [1] CRAN (R 3.5.3)                              
   sp               1.3-1      2018-06-05 [1] CRAN (R 3.5.1)                              
   stringi          1.4.3      2019-03-12 [1] CRAN (R 3.5.3)                              
   stringr        * 1.4.0      2019-02-10 [1] CRAN (R 3.5.2)                              
   tensorA        * 0.36.1     2018-07-29 [1] CRAN (R 3.5.1)                              
   tensorflow       1.10       2018-11-19 [1] CRAN (R 3.5.1)                              
   tfruns           1.4        2018-08-25 [1] CRAN (R 3.5.1)                              
   tibble         * 2.0.1      2019-01-12 [1] CRAN (R 3.5.2)                              
   tidyr          * 0.8.3      2019-03-01 [1] CRAN (R 3.5.3)                              
   tidyselect       0.2.5      2018-10-11 [1] CRAN (R 3.5.1)                              
   tidyverse      * 1.2.1      2017-11-14 [1] CRAN (R 3.5.3)                              
   usethis          1.4.0      2018-08-14 [1] CRAN (R 3.5.1)                              
   utf8             1.1.4      2018-05-24 [1] CRAN (R 3.5.1)                              
   vegan          * 2.5-4      2019-02-04 [1] CRAN (R 3.5.2)                              
   viridisLite      0.3.0      2018-02-01 [1] CRAN (R 3.5.1)                              
   weathercan     * 0.2.8      2018-10-08 [1] CRAN (R 3.5.1)                              
   whisker          0.3-2      2013-04-28 [1] CRAN (R 3.5.1)                              
   withr            2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                              
   xfun             0.5        2019-02-20 [1] CRAN (R 3.5.3)                              
   xml2             1.2.0      2018-01-24 [1] CRAN (R 3.5.1)                              
   yaml             2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                              

[1] C:/Users/essi/Documents/R/win-library/3.5
[2] C:/Program Files/R/R-3.5.3/library

 R -- Package was removed from disk.
boshek commented 5 years ago

👋 @essicolo

It is going to be difficult to diagnose this without a reprex. As a first step what if you added traceback() after the weathercan code?

essicolo commented 5 years ago

I know, sorry about that. I tried several things but never could reproduce it out in isolation. Here is the output.

> mont_bellevue <- weather_dl(station_ids = c(5397, 48371),
+                             start = "2019-02-01",
+                             end = "2019-02-07",
+                             interval = "hour",
+                             verbose = TRUE)
Getting station: 5397
Formatting station data: 5397
Error in strptime(xx, f, tz = tz) : invalid 'tz' value
> traceback()
8: strptime(xx, f, tz = tz)
7: as.POSIXlt.character(x, tz, ...)
6: as.POSIXlt(x, tz, ...)
5: as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...)
4: as.POSIXct.default(w$time, tz = tz)
3: as.POSIXct(w$time, tz = tz)
2: weather_format(w = w, preamble = preamble, stations = stations, 
       interval = interval, tz_disp = tz_disp, string_as = string_as, 
       quiet = quiet)
1: weather_dl(station_ids = c(5397, 48371), start = "2019-02-01", 
       end = "2019-02-07", interval = "hour", verbose = TRUE)
boshek commented 5 years ago

Very strange. I am not able to reproduce the bug using the same version of R. @steffilazerte might have some ideas. The offending line starts here:

https://github.com/ropensci/weathercan/blob/b3eaeceefd43adc260f92ce5cc442a7ca88fa6ee/R/weather.R#L465

However, on my machine the tz is specified correctly. Ideally you'd be able to re-run with a debug so that you can step into the function. On my machine tz here is "Etc/GMT+5".

essicolo commented 5 years ago

reprex succeeded!

Errors happen when an object named stations is created. The error message changes whether it's a data.frame or a scalar/vector/matrix.

> stations <- data.frame(A = 1)
> 
> library("weathercan")
> mont_bellevue <- weather_dl(station_ids = c(5397, 48371),
+                             start = "2019-02-01",
+                             end = "2019-02-07",
+                             interval = "hour",
+                             verbose = TRUE)
Getting station: 5397
Formatting station data: 5397
Error in strptime(xx, f, tz = tz) : valeur 'tz' incorrecte
boshek commented 5 years ago

@essicolo Do you want to test using this branch?

devtools::install_github("ropensci/weathercan", ref = "ref_internal_data")

essicolo commented 5 years ago

Ok, but here is another bug.

> library("weathercan")
> mont_bellevue <- weather_dl(station_ids = 48371,
+                             start = "2019-02-01",
+                             end = "2019-02-07",
+                             interval = "hour",
+                             verbose = TRUE)
Getting station: 48371
Formatting station data: 48371
Error in weather_format(w = w, preamble = preamble, stn = stn, interval = interval,  : 
  argument inutilisé (stn = stn)
steffilazerte commented 5 years ago

Okay, I pushed one more fix, I think this should do it :)

essicolo commented 5 years ago

It did do it. 👍