Re: [Rd] Creating functions programmatically

From: peter dalgaard <pdalgd_at_gmail.com>
Date: Wed, 03 Oct 2012 17:41:17 +0200

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:

>> Hadley,
>>
>> You could do this:
>>
>> make_fun = function(args, body, env)
>> {
>> f = function()
>> formals(f) = args
>> body(f) = body
>> environment(f) = env
>> f
>> }
>>
>> 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!
> 
> Hadley

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[[2]].

> 
> -- 
> RStudio / Rice University
> http://had.co.nz/
> 
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes_at_cbs.dk  Priv: PDalgd_at_gmail.com

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 03 Oct 2012 - 15:45:02 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 03 Oct 2012 - 21:00:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive