I have a complex function with many parameters. To make the code more readable, I thought that I could transfer the validation of input to some other function. As in the following example:
complex_function <- function(a=NA, b=NA, c=NA, d=NA, e=NA, f=NA, g=NA, h=NA) {
check_inputs(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h)
# ... rest of the function
}
check_inputs= function(a=NA, b=NA, c=NA, d=NA, e=NA, f=NA, g=NA, h=NA) {
if(is.na(a) & is.na(c)) {
stop("Not valid inputs - message 1")
} else if (is.na(h)) {
stop("Not valid inputs - message 2")
}
# long list of other controls
}
Is it possible to call check_inputswithout explicitly specifying all parameters? Something like check_inputs(get_all_arguments_of_parrent_function)? Is there a better way to approach this?
source
share