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 bol...@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 }
signature.asc
Description: OpenPGP digital signature
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel