R: force function execution with unused arguments

Viewed 20

I have a function that depends on some arguments, say, as a dummy example, that f <- function(t) t. I want to execute f provided a set of parameters in the list args. However, when args happens to have an argument u different than t the execution of do.call(f, args) outputs the error Error do.call(f, args) : unused argument (u = 3). This is the code:

f <- function(t) t
args <- list(t = 1, u = 3)
do.call(f, args)
# Error do.call(f, args) : unused argument (u = 3)

Instead, I want the function to ignore this error and be executed under t = 1, returning 1 in this case.

0 Answers
Related