Re: [R] Partial Function Application

2010-08-06 Thread Mog
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,

Re: [R] Partial Function Application

2010-08-06 Thread baptiste AuguiƩ
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) }

Re: [R] Partial Function Application

2010-08-06 Thread David Winsemius
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

[R] Partial Function Application

2010-08-06 Thread Mog
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

Re: [R] Partial function application in R

2009-03-12 Thread nosek
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

Re: [R] Partial function application in R

2009-01-17 Thread Wacek Kusnierczyk
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

Re: [R] Partial function application in R

2009-01-17 Thread nosek
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

Re: [R] Partial function application in R

2009-01-15 Thread Wacek Kusnierczyk
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(...)

Re: [R] Partial function application in R

2009-01-15 Thread Gabor Grothendieck
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,

Re: [R] Partial function application in R

2009-01-15 Thread nosek
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

Re: [R] Partial function application in R

2009-01-15 Thread Gabor Grothendieck
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

Re: [R] Partial function application in R

2009-01-15 Thread David Winsemius
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

[R] Partial function application in R

2009-01-15 Thread nosek
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