[Rd] Creating functions programmatically
pdalgd at gmail.com
Wed Oct 3 17:41:17 CEST 2012
On Oct 3, 2012, at 16:49 , Hadley Wickham wrote:
> On Wed, Oct 3, 2012 at 9:33 AM, Gabriel Becker <gmbecker at ucdavis.edu> wrote:
>> You could do this:
>> make_fun = function(args, body, env)
>> f = function()
>> formals(f) = args
>> body(f) = body
>> environment(f) = env
>> If for some reason using function() itself as Duncan suggested won't work.
> Oh that's an approach that's easier to explain to others - thanks!
There's also as.function(), although its semantics are a bit arcane. It and the converse as.list.function() have their origin in S-PLUS, where it was commonplace (or relatively so) to treat a function as a list, like in ls[].
> RStudio / Rice University
> R-devel at r-project.org mailing list
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-devel