[Rd] Curry: proposed new functional programming, er, function.

Ravi Varadhan rvaradhan at jhmi.edu
Wed May 4 16:40:16 CEST 2011


I too would like this (being an Indian!).

Here is an example that came up just yesterday with regards to solving a quadrature problem using the "cubature" package.  The adaptIntegrate function does not allow additional arguments via ...

Uwe suggested a work around, but `Curry' would solve it nicely (and it also tastes better!):

Curry = function(FUN,...) { 
.orig = list(...)
function(...) do.call(FUN,c(.orig, list(...))) 
}

require(cubature)

f <- function(x, a) cos(2*pi*x*a)  # a simple test function

# this works
a <- 0.2
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2)

# but this doesn't work
rm(a)
adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2, a=0.2)


# Use of Curry
adaptIntegrate(Curry(f, a=0.2), lower=0, upper=2)

Best,
Ravi.

-------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


-----Original Message-----
From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Hadley Wickham
Sent: Wednesday, May 04, 2011 10:29 AM
To: Byron Ellis
Cc: R Development Mailing List
Subject: Re: [Rd] Curry: proposed new functional programming, er, function.

I thought I might bring this up again - it now seems like Curry would
be a natural fit with Reduce, Filter, Find, Map, Negate and Position.
Any chance we might see this in a future version of R?

Hadley

On Thu, Nov 1, 2007 at 2:00 PM, Byron Ellis <byron.ellis at gmail.com> wrote:
> Hi all (especially R-core) I suppose,
>
> With the introduction of the new functional programming functions into
> base I thought I'd ask for a Curry() function. I use a simple one that
> looks this:
>
> Curry = function(FUN,...) { .orig = list(...);function(...)
> do.call(FUN,c(.orig,list(...))) }
>
> This comes in really handy when using say, heatmap():
>
> heatmap(mydata,hclustfun=Curry(hclust,method="average"))
>
> or other functions where there are ... arguments, but it's not clear
> where they should end up.
>
> --
> Byron Ellis (byron.ellis at gmail.com)
> "Oook" -- The Librarian
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
R-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list