mikejohnson51 / climateR

An R 📦 for getting point and gridded climate data by AOI
https://mikejohnson51.github.io/climateR/
MIT License
168 stars 40 forks source link

issue with getTerraClim readme-example #35

Closed mathiasweidinger closed 3 years ago

mathiasweidinger commented 3 years ago

Just got started with AOI and climateR. I tried to replicate the global data example from the climateR readme:

kenya = aoi_get(country = "Kenya")
tc = getTerraClim(kenya, param = "prcp", startDate = "2018-01-01")

The first line worked, but the second one gave me the following error.

Error in var[[i]] * scale_factor : 
non-numeric argument to binary operator

I'm uncertain to what operator it is referring...can you help me to resolve this?

(I run R version 4.0.4 (2021-02-15) on Win10)

Thanks in advance!

mikejohnson51 commented 3 years ago

Hi @mathiasweidinger,

Thanks for checking things out! I suspect you need to reinstall the most up to date version,

remotes::install_github("mikejohnson51/climateR", force = TRUE)

and that should allow you get a result like this:

library(AOI)
library(climateR)
library(raster)
#> Loading required package: sp
kenya = aoi_get(country = "Kenya")
tc = getTerraClim(kenya, param = "prcp", startDate = "2018-01-01")
raster::plot(tc$terraclim_prcp)

Created on 2021-04-21 by the reprex package (v1.0.0)

Hope it helps!

Mike

mathiasweidinger commented 3 years ago

Thanks @mikejohnson51 for the swift reply.

I just reinstalled and also made sure to load nothing beyond the basic working example. Unfortunately, the issue persists. Any other ideas what might cause this?

cheers

mikejohnson51 commented 3 years ago

Did you restart your R session after reinstalling? 🤞 that works, otherwise, could you post your package info and a small reprex (like above) and I will dive in to it!

mathiasweidinger commented 3 years ago

I restarted both my R session and my computer...still the same issue. Weirdly enough I replicated the exact same thing on the RStudio cloud and it worked fine - must be my system.

Here is the reprex including the package info in the toggle towards the end.

library(climateR)
library(AOI)
library(sp)
library(raster)

kenya = aoi_get(country = "Kenya")
tc = getTerraClim(kenya, param = "prcp", startDate = "2018-01-01")
#> Error in var[[i]] * scale_factor: non-numeric argument to binary operator

Created on 2021-04-21 by the reprex package (v2.0.0)

Session info ``` r sessionInfo() #> R version 4.0.4 (2021-02-15) #> Platform: i386-w64-mingw32/i386 (32-bit) #> Running under: Windows 10 x64 (build 19042) #> #> Matrix products: default #> #> locale: #> [1] LC_COLLATE=English_United Kingdom.1252 #> [2] LC_CTYPE=English_United Kingdom.1252 #> [3] LC_MONETARY=English_United Kingdom.1252 #> [4] LC_NUMERIC=C #> [5] LC_TIME=English_United Kingdom.1252 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] raster_3.4-5 sp_1.4-5 AOI_0.2.0.9000 climateR_0.1.0 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_1.0.6 rnaturalearth_0.1.0 lattice_0.20-41 #> [4] class_7.3-18 ps_1.6.0 assertthat_0.2.1 #> [7] digest_0.6.27 foreach_1.5.1 utf8_1.2.1 #> [10] mime_0.10 R6_2.5.0 USAboundaries_0.3.1 #> [13] leaflet.extras_1.0.0 reprex_2.0.0 evaluate_0.14 #> [16] e1071_1.7-6 httr_1.4.2 highr_0.9 #> [19] pillar_1.6.0 rlang_0.4.10 rstudioapi_0.13 #> [22] rmarkdown_2.7 stringr_1.4.0 htmlwidgets_1.5.3 #> [25] shiny_1.6.0 proxy_0.4-25 httpuv_1.5.5 #> [28] compiler_4.0.4 xfun_0.22 pkgconfig_2.0.3 #> [31] rgeos_0.5-5 htmltools_0.5.1.1 tidyselect_1.1.0 #> [34] tibble_3.1.1 codetools_0.2-18 fansi_0.4.2 #> [37] later_1.1.0.1 crayon_1.4.1 dplyr_1.0.5 #> [40] withr_2.4.2 sf_0.9-8 grid_4.0.4 #> [43] xtable_1.8-4 jsonlite_1.7.2 lifecycle_1.0.0 #> [46] DBI_1.1.1 magrittr_2.0.1 units_0.7-1 #> [49] KernSmooth_2.23-18 cli_2.4.0 stringi_1.5.3 #> [52] promises_1.2.0.1 fs_1.5.0 leaflet_2.0.4.1 #> [55] doParallel_1.0.16 xml2_1.3.2 ellipsis_0.3.1 #> [58] generics_0.1.0 vctrs_0.3.7 iterators_1.0.13 #> [61] tools_4.0.4 glue_1.4.2 RNetCDF_2.4-2 #> [64] purrr_0.3.4 crosstalk_1.1.1 fastmap_1.1.0 #> [67] parallel_4.0.4 yaml_2.2.1 classInt_0.4-3 #> [70] rvest_1.0.0 knitr_1.32 ```

I really appreciate your time and help - thanks a lot!

mikejohnson51 commented 3 years ago

Hi @mathiasweidinger looking at that output I don't see anything off. That was an error that I thought to be handled a few commits back ... The last step might be to just delete the current install of climateR (e.g. remove.packages("climateR") and try to refresh it. I am sorry this is giving you a challenge and hope its worth it in the end!

mathiasweidinger commented 3 years ago

Hey @mikejohnson51, I'm not sure what exactly caused the issue in the end but after a bit more tinkering I removed all non-base packages and now it works. Thanks for your help and have a good one!