Construct a function with argments specified by an R expression

Rolf Turner <[email protected]>
Newsgroups gmane.comp.lang.r.general
Message-ID <20251025152318.0d64a2bf@new-hp>
I want to build a function (say "buildFn") to *return* a function of the
form

    foo(x,y,a1, ... an, b1, ..., bn)

where the arguments ai and bi are given in the form of a list created
in R.  E.g. I'd like to be able to say

     argnms <- c(paste0("a",1:3),paste0("b",1:3"))
     foo <- buildFn(argnms)

with the resulting "foo" having arguments x, y, a1, a2, a3, b1, b2, b3.

I thought I might be able to do this using "formals<-" but I cannot get
this to work.  i could provide more detail of what I've tried, but it's
probably not worth it.

Can anyone steer me in the right direction?  Thanks.

cheers,

Rolf Turner

-- 
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.