[R] Partial Function Application
baptiste Auguié
baptiste.auguie at googlemail.com
Fri Aug 6 16:20:03 CEST 2010
Hi,
I think you mean Currying, there's a function in roxygen that looks like,
Curry
function (f, ..., .left = TRUE)
{
.orig = list(...)
function(...) {
if (.left) {
args <- c(.orig, list(...))
}
else {
args <- c(list(...), .orig)
}
do.call(f, args)
}
}
HTH,
baptiste
On Aug 6, 2010, at 3:56 PM, Mog wrote:
> Hi. I would like to partially apply a function to a list of arguments,
> and I don't know how to do this in R, without perhaps writing default
> values to the formals() of my function, or writing to the environment
> object of a function. For context, my definition of partially apply
> is: "fix some of the arguments, leaving the others as variables,
> return a new function that takes the un-fixed arguments from the
> original function as arguments"
>
> The issue is that I would like several different sets of arguments for
> the "partially applied" phase, and I think that would involve copying
> the function to several different places with the above methods.
>
> Alternately, I could hard-code the partial applications using a
> function() form, but I would prefer not to do this, as there will be a
> sizable number of these closures needed and I'd prefer to automate the
> process.
>
> Thanks!
>
> --Mog
>
> ______________________________________________
> 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