[Zooimage-commits] r94 - pkg/zooimage/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 21 11:22:26 CEST 2009


Author: romain
Date: 2009-04-21 11:22:26 +0200 (Tue, 21 Apr 2009)
New Revision: 94

Modified:
   pkg/zooimage/R/ZIRes.r
   pkg/zooimage/R/utilities.r
Log:
rework list.add using Reduce so that it can list.add more than two lists

Modified: pkg/zooimage/R/ZIRes.r
===================================================================
--- pkg/zooimage/R/ZIRes.r	2009-04-21 09:19:18 UTC (rev 93)
+++ pkg/zooimage/R/ZIRes.r	2009-04-21 09:22:26 UTC (rev 94)
@@ -158,15 +158,7 @@
 	# Determine the number of images in this sample
 	imgs <- unique(ZIDat$Label)
 	
-	add <- function( x ){
-		if( length(x) == 1 ) return( x[[1]] )
-		out <- x[[1]]
-		n <- length( x[[1]] )
-		lapply( 1:n, function(i){
-			Reduce( "+", lapply( x , "[[", i  ) )
-		} )
-	}
-	res <- add( lapply( imgs, function(im){
+	res <- list.add( lapply( imgs, function(im){
 		Spectrum(Smp, imgs[1], taxa = taxa, groups = groups, 
 			breaks = breaks, use.Dil = use.Dil)
 	} ) )

Modified: pkg/zooimage/R/utilities.r
===================================================================
--- pkg/zooimage/R/utilities.r	2009-04-21 09:19:18 UTC (rev 93)
+++ pkg/zooimage/R/utilities.r	2009-04-21 09:22:26 UTC (rev 94)
@@ -424,17 +424,15 @@
 # }}}
 
 # {{{ Add items across two lists (names must be the same)
-"list.add" <- function(x, y) {
-	
-	mustbe(x, "list")
-	mustbe(y, "list")
-	mustmatch( names(x), names(y), "names of two lists must match!")
-	res <- x
-	for (i in 1:length(x)){
-		res[[i]] <- x[[i]] + y[[i]]
-	}
-	attributes(res) <- attributes(x)
-	return(res)	
+# not used
+list.add <- function( ..., .list = list(...) ){
+	if( length(.list) == 1 ) return( .list[[1]] )
+	n <- length( .list[[1]] )
+	out <- lapply( 1:n, function(i){
+		Reduce( "+", lapply( .list , "[[", i  ) )
+	} )
+	attributes( out ) <- attributes( .list[[1]] )
+	out
 }
 # }}}
 



More information about the Zooimage-commits mailing list