refactor: check the QupstrUnit argument using match.arg in CreateInputsModel
Refs #110
-
Developer
Is there a problem with the following situation ?
> QupstrUnit <- NULL > match.arg(arg = QupstrUnit, choices = c("mm", "m3", "m3/s", "l/s", "L/s")) [1] "mm"
It's maybe exaggerated but we should prevent that a
NULL
value make a choice be default that it is not known by the user. I suggest to adopt one of these solutions:if(is.null(QupstrUnit)) stop("QupstrUnit should be one of \"", paste(choices, collapse = "\", \""), "\"")
if(is.null(QupstrUnit)) warning("'QupstrUnit' has been redefined to \"mm\"")
-
Author Owner
Using
tolower(QupstrUnit)
fixed it and it allows to be flexible in the respect of the case of characters.> match.arg(arg = tolower(NULL), choices = c("mm", "m3", "m3/s", "l/s")) Error in match.arg(arg = tolower(NULL), choices = c("mm", "m3", "m3/s", : 'arg' doit être un de “mm”, “m3”, “m3/s”, “l/s” > match.arg(arg = NULL, choices = c("mm", "m3", "m3/s", "l/s")) [1] "mm"
I wasn't shocked by the previous behavior, because that's how the
match.arg()
function usually works. -
Author Owner
And it is a normal behavior in R to return the default value if the NULL value is used.