On 04/05/2011 10:40 AM, Ravi Varadhan wrote:
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)
Two objections:
1. I don't see how that is preferable to
adaptIntegrate(function(x) f(x, a=0.2), lower=0, upper=2)
2. There seems to be confusion about what currying means. The
Wikipedia page <http://en.wikipedia.org/wiki/Currying> indicates that
the function Curry() defined above is really doing "partial function
application", not currying. I'm in no position to judge whether Byron
got it right or Wikipedia did, but this suggests to me that the name
"Curry" is inappropriate, since at least some people who know what
currying is would not guess that it does what it does.
Duncan Murdoch
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: rvarad...@jhmi.edu
-----Original Message-----
From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@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.el...@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.el...@gmail.com)
> "Oook" -- The Librarian
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel