Programmatically create a function with the same arguments as another function

Hi,

I'm wondering if there is a programmatic way to create a new function that has the same arguments as another function. Let's say I wanted to create a function with the same arguments as lm()

Something like:

args <- as.list(names(formals(lm)))

foo <- function(!!!args) {
  # body
}

The code above doesn't work, but I'm wondering if there is a way to do this.

Sounds like you want what is called a function factory?

If so, look at: https://adv-r.hadley.nz/function-factories.html and also https://github.com/jonthegeek/factory