Open Pakillo opened 3 weeks ago
By now this could be a quick solution to get climate for a specific period for each site:
df <- data.frame(lon = c(-5, -5),
lat = c(37, 38),
period = c("2010-01-01",
"2020-01-01"))
df.list <- split(df, 1:nrow(df))
clim_by_row <- function(row, climvar = "Prcp") {
easyclimate::get_daily_climate(row, period = row$period,
climatic_var = climvar,
check_connection = FALSE)
}
output <- lapply(df.list, clim_by_row, climvar = "Prcp")
#>
#> Downloading Prcp data... This process might take several minutes
#>
#> Downloading Prcp data... This process might take several minutes
do.call("rbind", output)
#> ID_coords period lon lat date Prcp
#> 1 1 2010-01-01 -5 37 2010-01-01 0
#> 2 1 2020-01-01 -5 38 2020-01-01 0
Created on 2024-09-25 with reprex v2.1.1
A student came to me with a problem where he had about a hundred sites and wanted to get climate for a specific period for each site. Currently, if you provide a 'period` vector of the same length as the number of sites (i.e. nrow(coords)), the periods will be recycled, so that each site gets the climate for the whole period vector.
I think it would be nice to be able to provide a data frame with sites/coords and a same-length vector of 'period' desired for each site. But I don't know how easy/feasible that is given current use of 'period'.
Reprex:
Created on 2024-09-25 with reprex v2.1.1