[R] Partial function application in R
nosek
nospamek at interia.pl
Fri Jan 16 23:13:51 CET 2009
Hello,
soon after my last posting to this thread I stumbled upon the do.call
function and came to the very much the same version as yours. It is good!
However, it looks that both name clashes and mixing keyword and positional
styles in argument binding and function calls may lead to very drastic and
cryptic errors. Therefore I find this "functional" style of programming not
too reliable yet.
Wacek Kusnierczyk wrote:
>
> czesc,
>
> looks like you want some sort of currying, or maybe partial currying,
> right? anyway, here's a quick guess at how you can modify your bind,
> and it seems to work, as far as i get your intentions, with the plot
> example you gave:
>
> bind = function(f, ...) {
> args = list(...)
> function(...) do.call(f, c(list(...), args)) }
>
> plotlines = bind(plot, type='l')
> plotlines(1:10, runif(10))
>
> plotredlines = bind(plotlines, col="red")
> plotredlines(runif(10))
>
> # careful about not overriding a named argument
> plotredpoints = bind(plotredlines, type="p")
> plotredpoints(runif(10))
>
> you may want to figure out how to get rid of the smart y-axis title.
> is this what you wanted?
>
> pzdr,
> vQ
>
>
--
View this message in context: http://www.nabble.com/Partial-function-application-in-R-tp21487269p21509532.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list