Skip to content
Prev 167181 / 398502 Next

Partial function application in R

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
nosek wrote: