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

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.