Skip to content
Prev 173459 / 398502 Next

Partial function application in R

Sorry for not answering long. After working a lot with new version of "bind"
function I find it actually really useful. Just to avoid any possible
hard-to-debug errors I try to stick to some good practices, like always
specifying default values for formal parameters and calling "bind" with
named arguments only.

And actually this feature reinvents
http://www.nabble.com/Curry%3A-proposed-new-functional-rogramming%2C-er%2C-function.-td13535544.html#a13535544
:)

I find myself operating a lot with list-of-lists-like structures, so this
facility helps me really a lot. What about this one:

combine <- function( ... ) {
  funs <- list( ... )
  head <- funs[[1]]
  NULL -> funs[[1]]
  if( length(funs) > 0 )
    function( ... )
      do.call( combine, funs ) ( head( ... ) )
  else head
}

It helps me to avoid lapplying multiple functions one after another, which
was not really readable. Thus I came to writing code like this:

sorting.predicate <- combine( pure.perf, bind( "[[", i="V11"), bind(
quantile, 0.25 ) )

I wonder how bad is it? :)

Regards,
 nosek
Wacek Kusnierczyk wrote: