validate_dots {dreamerr} | R Documentation |
Checks the arguments in dots from methods
Description
This function informs the user of arguments passed to a method but which are not used by the method.
Usage
validate_dots(
valid_args = c(),
suggest_args = c(),
message,
warn,
stop,
call. = FALSE,
immediate. = TRUE
)
Arguments
valid_args |
A character vector, default is missing. Arguments that are not in the definition of the function but which are considered as valid. Typically internal arguments that should not be directly accessed by the user. |
suggest_args |
A character vector, default is missing. If the user provides invalid arguments, he might not be aware of the main arguments of the function. Use this argument to inform the user of these main arguments. |
message |
Logical, default is |
warn |
Logical, default is |
stop |
Logical, default is |
call. |
Logical, default is |
immediate. |
Logical, default is |
Value
This function returns the message to be displayed. If no message is to be displayed because all the arguments are valid, then NULL
is returned.
Examples
# The typical use of this function is within methods
# Let's create a 'my_class' object and a summary method
my_obj = list()
class(my_obj) = "my_class"
# In the summary method, we add validate_dots
# to inform the user of invalid arguments
summary.my_class = function(object, arg_one, arg_two, ...){
validate_dots()
# CODE of summary.my_class
invisible(NULL)
}
# Now let's test it, we add invalid arguments
summary(my_obj, wrong = 3)
summary(my_obj, wrong = 3, info = 5)
# Now let's :
# i) inform the user that argument arg_one is the main argument
# ii) consider 'info' as a valid argument (but not shown to the user)
# iii) show a message instead of a warning
summary.my_class = function(object, arg_one, arg_two, ...){
validate_dots(valid_args = "info", suggest_args = "arg_one", message = TRUE)
# CODE of summary.my_class
invisible(NULL)
}
# Let's retest it
summary(my_obj, wrong = 3) # not OK => suggestions
summary(my_obj, info = 5) # OK