Commit 77fa9c32 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

refactor: check the QupstrUnit argument using match.arg in CreateInputsModel

Refs #110
Showing with 1 addition and 3 deletions
+1 -3
  • 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\"")
    Edited by Dorchies David
  • 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.

  • And it is a normal behavior in R to return the default value if the NULL value is used.

    Edited by Delaigue Olivier
Supports Markdown
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