Consider the following toy function
my_function <- function(arg_1, new_arg_2){
string <- paste(arg_1, new_arg_2, sep = " ")
return(string)
}
It has two arguments arg_1
and new_arg_2
. They work great.
my_function(arg_1 = "Hello", new_arg_2 = "World!")
[1] "Hello World!"
Presumably though my_function
previously had an argument called arg_2
, which has since been replaced with new_arg_2
.
Running the function using the (old, now nonexistent) argument arg_2
naturally produces an error
my_function(arg_1 = "Hello", arg_2 = "World!")
Error in my_function(arg_1 = "Hello", arg_2 = "World!") : unused argument (arg_2 = "World!")
What I want is to change this error message so that it says something else, like
"You have supplied arg_2, perhaps you meant to supply new_arg_2"
Somewhat similar to this question except that I want to evaluate the arguments passed to a function inside the function while it's running, rather than getting the expected function names from a non-running function.
How can I do this?