The validate() function
The name of this function is definitely self-explanatory. In almost all the cases and except for extremely rare occasions, validate()
is used along with need()
, which is an easy wrapper that evaluates an expression in an extended way and produces an error message.
The expression evaluation performed by need()
is extended with respect to normal condition evaluation in R, because it evaluates to False
(and displays an error message) if the evaluation returns NA or the passed variable is empty. need()
has two arguments for the error message: message
and label
. The first one is simply the text to be displayed and the second one is a character that can be used to be inserted dynamically into the error message. By default, message is paste(label, "must be provided")
, so it expects the label argument. However, if message is passed, label is ignored. It is normally recommended to directly specify message.
Looking at Example 1 again, this could be a good need()
statement to...