fun <- function(values_i_3m) {
verifyFunctionArguments(mget(ls()), FALSE, FALSE)
}
fun(1)
# [1] FALSE
fun(1:7)
# [1] TRUE
nonOPFun <- function(x) {
verifyFunctionArguments(mget(ls()), FALSE, TRUE)
}
nonOPFun(1:7)
# $x
# [1] 1 2 3 4 5 6 7
#
# x FALSE unknown suffix, [NA]
#
# [1] FALSE
# real use case with abortion
myFunWithAbortion <- function(values_i_3m) {
verifyFunctionArguments(mget(ls()))
# ...
}
tryCatch(myFunWithAbortion(1), error = function(e) cat(e$message, '\n'))
# argument mistmatch [values_i_3m] wrong length, was expecting [3m] , got [1]
# real use case without abortion
myFunWithoutAbortion <- function(values_i_3m) {
if (!verifyFunctionArguments(mget(ls()), FALSE)) return(FALSE)
cat('continuing processing ...\n')
TRUE
}
myFunWithoutAbortion(1)
# FALSE
myFunWithoutAbortion(1:3)
# continuing processing ...
# TRUE
Run the code above in your browser using DataLab