DrylandEcology / rSOILWAT2

A R package for SOILWAT2
GNU General Public License v3.0
10 stars 4 forks source link

`dbW_dataframe_to_weatherData()` is not backwards compatible with `v6.0.0` #236

Closed dschlaep closed 1 year ago

dschlaep commented 1 year ago

dbW_dataframe_to_weatherData() is not backwards compatible with v6.0.0.

see https://github.com/DrylandEcology/rSW2metrics/issues/9

This function must be able to "upgrade" a data frame that lacks "non-essential" variables such that it becomes backwards compatible and the following use is possible (again):

set.seed(54)
N <- 365
doys <- seq_len(N)
tmean <- -5 + 20 * sinpi(doys / N) + rnorm(n = N, sd = 2)

tmp_meteo <- cbind(
  Year = rep(2019, times = N),
  DOY = doys,
  Tmax_C = tmean + 4 + rnorm(n = N, sd = 1),
  Tmin_C = tmean - 4 + rnorm(n = N, sd = 1),
  PPT_cm = 0.1 * rgamma(n = N, shape = 1, rate = 1)
)

rSOILWAT2::dbW_dataframe_to_weatherData(tmp_meteo)

Current error

Not every weatherDF_dataColumns is available in the 'weatherDF' object

Or at least for use cases such as

rSOILWAT2::dbW_dataframe_to_weatherData(
  tmp_meteo,
  weatherDF_dataColumns = c("DOY", "Tmax_C", "Tmin_C", "PPT_cm")
)

Current error

Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent