[Rd] Reduce: extra args wishlist? from Ben Bolker on 2009-06-07 (R devel archive)

[Rd] Reduce: extra args wishlist?

From: Ben Bolker <bolker_at_ufl.edu>
Date: Sat, 06 Jun 2009 18:45:33 -0400

  Is there a reason that Reduce() doesn't take a "..." argument that would allow arbitrary extra arguments to be passed through to the function?

  Here is a little example of how this would be convenient:

z <- list(

          data.frame(state=c("California"),
                     cases=0),
          data.frame(state=c("California","Massachusetts"),
                     cases=c(1,2)),
          data.frame(state=c("California","Massachusetts","Arizona"),
                     cases=c(1,2,17)))

## read in revised version of Reduce()
Reduce(merge,z,by="state",all=TRUE)

  The change is simple -- just add "..." to every call to the function in Reduce() -- patch is included below my signature ...

  It's not a big deal -- I could also do Reduce(function(x,y) { merge(x,y,by="state",all=TRUE) }, z) but there doesn't seem to be a good reason not to allow it ...

  cheers
    Ben Bolker

-- 
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bolker_at_ufl.edu / www.zoology.ufl.edu/bolker
GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc


*** /home/ben/funprog.R.new	2009-06-06 18:30:56.000000000 -0400

--- src/library/base/R/funprog.R 2009-02-12 10:39:32.000000000 -0500
*************** *** 15,21 **** # http://www.r-project.org/Licenses/ Reduce <- ! function(f, x, init, right = FALSE, accumulate = FALSE, ...) { mis <- missing(init) len <- length(x)
--- 15,21 ----
# http://www.r-project.org/Licenses/ Reduce <- ! function(f, x, init, right = FALSE, accumulate = FALSE) { mis <- missing(init) len <- length(x) *************** *** 47,57 **** if(!accumulate) { if(right) { for(i in rev(ind)) ! init <- f(x[[i]], init, ...) } else { for(i in ind) ! init <- f(init, x[[i]], ...) } init }
--- 47,57 ----
if(!accumulate) { if(right) { for(i in rev(ind)) ! init <- f(x[[i]], init) } else { for(i in ind) ! init <- f(init, x[[i]]) } init } *************** *** 64,76 **** if(right) { out[[len]] <- init for(i in rev(ind)) { ! init <- f(x[[i]], init, ...) out[[i]] <- init } } else { out[[1L]] <- init for(i in ind) { ! init <- f(init, x[[i]], ...) out[[i]] <- init } }
--- 64,76 ----
if(right) { out[[len]] <- init for(i in rev(ind)) { ! init <- f(x[[i]], init) out[[i]] <- init } } else { out[[1L]] <- init for(i in ind) { ! init <- f(init, x[[i]]) out[[i]] <- init } } *************** *** 78,91 **** if(right) { out[[len]] <- init for(i in rev(ind)) { ! init <- f(x[[i]], init, ...) out[[i]] <- init } } else { for(i in ind) { out[[i]] <- init ! init <- f(init, x[[i]], ...) } out[[len]] <- init }
--- 78,91 ----
if(right) { out[[len]] <- init for(i in rev(ind)) { ! init <- f(x[[i]], init) out[[i]] <- init } } else { for(i in ind) { out[[i]] <- init ! init <- f(init, x[[i]]) } out[[len]] <- init }

______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

Received on Sat 06 Jun 2009 - 22:53:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 10 Jun 2009 - 15:05:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive