Commit ab143426 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

Merge branch '45-replace-the-use-of-class-by-inherits-in-order-to-test-the-classes' into 'dev'

Resolve "Replace the use of 'class' by 'inherits' in order to test the classes of inputs"

Closes #45

See merge request !21
parents e088b828 63b9e688
Pipeline #26088 passed with stage
in 1 minute and 44 seconds
......@@ -5,14 +5,14 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
CalCrit <- sprintf("ErrorCrit_%s", CalCrit)
FUN_CRIT <- get(CalCrit)
if (! any(transfo %in% c("", "sqrt", "log", "inv", "sort"))) {
if (!any(transfo %in% c("", "sqrt", "log", "inv", "sort"))) {
stop("Non convenient transformation \"transfo\"")
} else {
transfo <- transfo[1L]
}
if (! any(class(PrepGR) %in% "PrepGR")) {
if (!inherits(PrepGR, "PrepGR")) {
stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"")
}
......
......@@ -44,7 +44,7 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q
TempMean = TempMean)
}
if (! any(attributes(ObsDF$DatesR[1])$tzone %in% "UTC")) {
if (!any(attributes(ObsDF$DatesR[1])$tzone %in% "UTC")) {
stop("Non convenient date format. Time zone must be defined as \"UTC\"")
}
......
......@@ -5,14 +5,14 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2",
EffCrit <- sprintf("ErrorCrit_%s", EffCrit)
FUN_CRIT <- get(EffCrit)
if (! any(transfo %in% c("", "sqrt", "log", "inv", "sort"))) {
if (!any(transfo %in% c("", "sqrt", "log", "inv", "sort"))) {
stop("Non convenient transformation \"transfo\"")
} else {
transfo <- transfo[1L]
}
if (! any(class(PrepGR) %in% "PrepGR")) {
if (!inherits(PrepGR, "PrepGR")) {
stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"")
}
......@@ -23,7 +23,7 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2",
if (missing(Param)) {
Param <- NULL
}
if (! any(class(CalGR) %in% "CalGR") & !is.null(CalGR)) {
if (!inherits(CalGR, "CalGR") & !is.null(CalGR)) {
stop("Non convenient data for argument \"CalGR\". Must be of class \"CalGR\"")
}
if (is.null(CalGR) & is.null(Param)) {
......
......@@ -81,7 +81,7 @@ if (getRversion() >= "2.15.1") {
if (!is.list(x)) {
x <- list(TypeModel = x)
}
if (any(class(x) %in% c("PrepGR", "CalGR", "SimGR")) || names(x) %in% "TypeModel") {
if (inherits(x, c("PrepGR", "CalGR", "SimGR")) || names(x) %in% "TypeModel") {
x <- x$TypeModel
}
......
dyplot.CalGR <- function(x, ...) {
if (! any(class(x) %in% "CalGR")) {
if (!inherits(x, "CalGR")) {
stop("Non convenient data for x argument. Must be of class \"CalGR\"")
}
......
dyplot.PrepGR <- function(x, ...) {
if (! any(class(x) %in% "PrepGR")) {
if (!inherits(x, "PrepGR")) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\"")
}
......
dyplot.SimGR <- function(x, ...) {
if (! any(class(x) %in% "SimGR")) {
if (!inherits(x, "SimGR")) {
stop("Non convenient data for x argument. Must be of class \"SimGR\"")
}
......
......@@ -7,7 +7,7 @@ dyplot.default <- function(x, Qsup = NULL, Qsup.name = "Qsup",
# barChartPrecip <- scan(file = system.file("plugins/barChartPrecip.js", package = "airGRteaching"),
# what = "character", quiet = TRUE)
if (! any(class(x) %in% c("PrepGR", "CalGR", "SimGR"))) {
if (!inherits(x, c("PrepGR", "CalGR", "SimGR"))) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\", \"CalGR\" or \"SimGR\"")
}
......@@ -34,7 +34,7 @@ dyplot.default <- function(x, Qsup = NULL, Qsup.name = "Qsup",
}
if (any(class(x) %in% "PrepGR")) {
if (inherits(x, "PrepGR")) {
data <- data.frame(DatesR = x$InputsModel$DatesR,
Precip = x$InputsModel$Precip,
Qobs = x$Qobs,
......
plot.CalGR <- function(x, xlab = NULL, ylab = NULL, main = NULL, which = c("perf", "iter", "ts"), ...) {
if (! any(class(x) %in% "CalGR")) {
if (!inherits(x, "CalGR")) {
stop("Non convenient data for x argument. Must be of class \"CalGR\"")
}
if (! any(which %in% c("perf", "iter", "ts"))) {
if (!any(which %in% c("perf", "iter", "ts"))) {
stop("Non convenient data for which argument. Must be of class \"perf\", \"iter\" or \"ts\"")
}
......
plot.PrepGR <- function(x, type = "l", col.Precip = "royalblue", col.Q = "black", col.na = "grey",
xlab = NULL, ylab = NULL, main = NULL, plot.na = TRUE, ...) {
if (! any(class(x) %in% "PrepGR")) {
if (!inherits(x, "PrepGR")) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\"")
}
......
plot.SimGR <- function(x, ...) {
if (! any(class(x) %in% "SimGR")) {
if (!inherits(x, "SimGR")) {
stop("Non convenient data for x argument. Must be of class \"SimGR\"")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment