# Example with computation being made within a non user-level function
sum_fun = function(x, y){
my_internal(x, y, sum = TRUE)
}
diff_fun = function(x, y){
my_internal(x, y, sum = FALSE)
}
my_internal = function(x, y, sum){
set_up(1) # => errors will be at the user-level function
check_arg(x, y, "numeric scalar mbt")
# Identical to calling
# check_arg(x, y, "numeric scalar mbt", .up = 1)
if(sum) return(x + y)
return(x - y)
}
# we check it works
sum_fun(5, 6)
diff_fun(5, 6)
# Let's throw some errors
try(sum_fun(5))
try(sum_fun(5, 1:5))
Run the code above in your browser using DataLab