Re: Construct a function with argments specified by an R expression
Rolf Turner <[email protected]>
| Newsgroups | gmane.comp.lang.r.general |
|---|---|
| Message-ID | <20251026090538.00c4e4ca@new-hp> |
On Sat, 25 Oct 2025 06:24:48 -0400 Duncan Murdoch <[email protected]> wrote: > Another way to do this is to make a prototype and then modify it. > For example, > > foo <- function(x, y, others) { > # the body can be anything, we won't touch it > } > > args <- formals(foo) > > # Make extra copies of the 3rd argument > args[3:(2 + length(argnms))] <- args[3] > > # Set the names of the new ones (or use Iris's code to set all the > names, your choice) > > names(args)[3:(2 + length(argnms))] <- argnms > > formals(foo) <- args > > Duncan Murdoch That saves my having to worry about quote() and expr. Ta. cheers, Rolf -- Honorary Research Fellow Department of Statistics University of Auckland Stats. Dep't. (secretaries) phone: +64-9-373-7599 ext. 89622 Home phone: +64-9-480-4619