Thank you! That's exactly what I wanted.
--Mog
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained,
Hi,
I think you mean Currying, there's a function in roxygen that looks like,
Curry
function (f, ..., .left = TRUE)
{
.orig = list(...)
function(...) {
if (.left) {
args <- c(.orig, list(...))
}
else {
args <- c(list(...), .orig)
}
On Aug 6, 2010, at 9:56 AM, Mog wrote:
Hi. I would like to partially apply a function to a list of arguments,
and I don't know how to do this in R, without perhaps writing default
values to the formals() of my function, or writing to the environment
object of a function. For context, my definit
Hi. I would like to partially apply a function to a list of arguments,
and I don't know how to do this in R, without perhaps writing default
values to the formals() of my function, or writing to the environment
object of a function. For context, my definition of partially apply
is: "fix some of the
Sorry for not answering long. After working a lot with new version of "bind"
function I find it actually really useful. Just to avoid any possible
hard-to-debug errors I try to stick to some good practices, like always
specifying default values for formal parameters and calling "bind" with
named a
nosek wrote:
> 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!
>
at least for the sort of tasks as in the examples below. but i haven't
tested it beyond those, and in r you shouldn't re
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
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(...)
One other idea. The proto package also does currying. If f a method
(i.e. an R function
that takes an object as arg1 then p$f, i.e. the $.proto function,
returns function(...) f(p, ...).
Looking at the code for setDefaults as in my prior response and/or
proto should give
you some ideas.
On Thu,
Well,
it looks like it's a perfectly correct approach to bind functions writing
their wrappers by hand.
But I don't want to write them by hand every time I need them.
Being lambda expression, function() is most general, but there must be some
kind of shorter way for such a common task as partial
Have a look at the setDefaults package. It will set the default
arguments of a function to whatever you specify so that
if you omit them then those are the values you get for them.
On Thu, Jan 15, 2009 at 4:25 PM, nosek wrote:
>
> Hello,
>
> in a desperate desire of using partial function applic
How is function() not the correct approach?
> plot_lines <- function(x, ...) plot(x, type="l", ...)
>
> plot_lines(1:10, xlim = c(1,5))
> plot_lines(1:10, 11:20, xlim = c(1,5))
Still seems to get the unnamed optional y argument to the plotting
machinery.
--
David Winsemius
On Jan 15, 2009
Hello,
in a desperate desire of using partial function application in R I fried out
the following piece of code:
bind <- function( f, ... ) {
args <- list(...)
function(...) f( ..., unlist(args) )
}
Its purpose, if not clear, is to return a function with part of its
arguments bound to speci
13 matches
Mail list logo