[R] Partial function application in R

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 16 02:26:57 CET 2009


One other idea.  The proto package also does currying.  If f a method
(i.e. an R function
that takes an object as arg1 then p$f, i.e. the $.proto function,
returns function(...) f(p, ...).
Looking at the code for setDefaults as in my prior response and/or
proto should give
you some ideas.

On Thu, Jan 15, 2009 at 6:43 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> Have a look at the setDefaults package.  It will set the default
> arguments of a function to whatever you specify so that
> if you omit them then those are the values you get for them.
>
> On Thu, Jan 15, 2009 at 4:25 PM, nosek <nospamek at interia.pl> wrote:
>>
>> Hello,
>>
>> in a desperate desire of using partial function application in R I fried out
>> the following piece of code:
>>
>> bind <- function( f, ... ) {
>>  args <- list(...)
>>  function(...) f( ..., unlist(args) )
>> }
>>
>> Its purpose, if not clear, is to return a function with part of its
>> arguments bound to specific values, so that I can for example create and use
>> functions like this:
>>  q1 <- bind( quantile, 0.25 )
>>  lapply( some_list, q1 )
>>
>> It's been a lot of work and unfortunately is not perfect. My bind applies
>> arguments only using positional rule. What I dream of is a function bind2
>> that would apply keyword arguments, like:
>>  plot_lines <- bind2( plot, type="l" )
>> which would return
>>  function(...) plot( type="l", ... )
>>
>> How to do this in R?
>>
>> Regards,
>> nosek
>> --
>> View this message in context: http://www.nabble.com/Partial-function-application-in-R-tp21487269p21487269.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>




More information about the R-help mailing list