Fix 'SimGR' tests when running on a non UTC timezone
From: Joshua Ulrich 3 November 2022 20:45
CC: Kurt Hornik
One package test fails when I run 'R CMD check' with a non-UTC timezone. I found this issue while running reverse-dependency checks for xts. I wanted to make sure it wasn't an xts bug.
There's a reproducible example below. Kurt found the issue is with the lines that compare dates with a character string, because the result is locale-dependent.
Let me know if you have questions.
# the expected result (a warning)
Sys.setenv(TZ="UTC")
require(airGRteaching)
data(L0123001, package = "airGR")
BasinObsSubNA <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]$Qmm <- NA
BasinObsTotNA <- BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]
PrepSubNA <- PrepGR(ObsDF = BasinObsSubNA, HydroModel = "GR4J", CemaNeige = FALSE)
PrepTotNA <- PrepGR(ObsDF = BasinObsTotNA, HydroModel = "GR4J", CemaNeige = FALSE)
object <- SimGR(PrepGR = PrepTotNA, Param = c(270.426, 0.984, 108.853, 2.149),
EffCrit = "KGE2", WupPer = c("1994-01-01", "1994-12-31"),
SimPer = c("1995-01-01", "1998-12-31")) ## Warning message:
## In SimGR(PrepGR = PrepTotNA, Param = c(270.426, 0.984, 108.853, :
## "PrepGR" does not contain any Qobs values. The efficiency criterion is not computed
# error if the timezone isn't UTC
Sys.setenv(TZ="America/Chicago")
require(airGRteaching)
data(L0123001, package = "airGR")
BasinObsSubNA <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]$Qmm <- NA
BasinObsTotNA <- BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]
PrepSubNA <- PrepGR(ObsDF = BasinObsSubNA, HydroModel = "GR4J", CemaNeige = FALSE)
PrepTotNA <- PrepGR(ObsDF = BasinObsTotNA, HydroModel = "GR4J", CemaNeige = FALSE)
object <- SimGR(PrepGR = PrepTotNA, Param = c(270.426, 0.984, 108.853, 2.149),
EffCrit = "KGE2", WupPer = c("1994-01-01", "1994-12-31"),
SimPer = c("1995-01-01", "1998-12-31")) ## Error in SimGR(PrepGR = PrepTotNA, Param = c(270.426, 0.984, 108.853, :
## Non convenient date for the warm-up period "WupPer"