[R] Partial function application in R
nosek
nospamek at interia.pl
Thu Jan 15 22:25:44 CET 2009
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.
More information about the R-help
mailing list