[R] Modifying a function programmatically

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 4 17:31:06 CET 2013


On Mon, Feb 4, 2013 at 5:00 AM, Søren Højsgaard <sorenh at math.aau.dk> wrote:
> Dear list
>
> # I have a function
>  ff  <- function(a,b=2,c=4){a+b+c}
> # which I programmatically want to modify to a more specialized function in which a is replaced by 1
>  ff1 <- function(b=2,c=4){1+b+c}
>

This a currying operation. Try:

library(functional)
ff1 <- Curry(ff, a = 1)

# test
identical(ff1(2, 4), ff(1, 2, 4)) # TRUE

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list