Closed ryanrbart closed 9 months ago
Hi @ryanrbart! Thanks for the kind words and the interesting use case. This involved changing how environments were handled but resulted in a nice simplification! The following should now work if reinstalled:
library(climateR)
sb_county <- AOI::aoi_get(state = "CA", county = "Santa Barbara")
wrapper_function <- function(aoi, var_name, start_date, end_date){
# My other code here
climateR::getGridMET(AOI = aoi,
varname = var_name,
startDate = start_date,
endDate = end_date,
dryrun = FALSE)
}
wrapper_function(aoi = sb_county, var_name = "pr", start_date = "2010-01-01", end_date = NULL)
#> $precipitation_amount
#> class : SpatRaster
#> dimensions : 42, 43, 1 (nrow, ncol, nlyr)
#> resolution : 0.04166667, 0.04166667 (x, y)
#> extent : -120.7458, -118.9542, 33.37917, 35.12917 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +ellps=WGS84 +no_defs
#> source(s) : memory
#> name : pr_2010-01-01
#> min value : 0
#> max value : 0
#> unit : mm
#> time : 2010-01-01 UTC
wrapper_function(aoi = sb_county, var_name = "tmmx", start_date = "2020-01-01", end_date = NULL)
#> $daily_maximum_temperature
#> class : SpatRaster
#> dimensions : 42, 43, 1 (nrow, ncol, nlyr)
#> resolution : 0.04166667, 0.04166667 (x, y)
#> extent : -120.7458, -118.9542, 33.37917, 35.12917 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=longlat +ellps=WGS84 +no_defs
#> source(s) : memory
#> name : tmmx_2020-01-01
#> min value : 282.2
#> max value : 293.8
#> unit : K
#> time : 2020-01-01 UTC
Created on 2023-12-21 with reprex v2.0.2
@mikejohnson51, the simplification of the environments has fixed the issue. Everything is working properly on my end. Thanks for taking the time to quickly respond to the issue.
Hi Mike. Thanks for developing this package. It's fantastic.
I would like to embed some of the climateR functions within my workflows, so that I can more easily fetch the data that I want. Here is a simple example of what I want to do.
Unfortunately, adding a wrapper around getGridMET generates an error. It seems to be related to the environment. In the following example, I define new variables in the global environment, but still pass the original variables to the function. The wrapper now works, but incorrectly by grabbing the variables from the global environment and not the variables being passed to the function.
Note that the output is daily maximum temperature and includes two dates, not one.
Any assistance is much appreciated.
Thanks, Ryan