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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 27 10:03:14 CEST 2009


Author: romain
Date: 2009-04-27 10:03:12 +0200 (Mon, 27 Apr 2009)
New Revision: 108

Modified:
   pkg/zooimage/R/utilities.r
Log:
simplifying list.merge

Modified: pkg/zooimage/R/utilities.r
===================================================================
--- pkg/zooimage/R/utilities.r	2009-04-27 07:52:37 UTC (rev 107)
+++ pkg/zooimage/R/utilities.r	2009-04-27 08:03:12 UTC (rev 108)
@@ -373,8 +373,7 @@
 #' Merge two lists of data frames
 "list.merge" <- function(x, y) {
 	
-	mustbe( x, "list" )
-	mustbe( y, "list" )
+	mustallbe( x, y, class = "list" )
 	
 	xitems <- names(x)
 	yitems <- names(y)
@@ -382,31 +381,23 @@
 	xonly <- xitems[!(xitems %in% xandy)]
 	yonly <- yitems[!(yitems %in% xandy)]
 	
-	# construct the merged list
-	res <- list()
-	
 	# First merge common items
 	if (length(xandy) > 0) {
-		for (i in 1:length(xandy)){
-			item <- xandy[i] 
-			res[[ item ]] <- merge(x[[ item ]], y[[ item ]], all = TRUE)
-		}
+		res <- lapply( xandy, function(item){
+			merge( x[[item]], y[[item]], all = TRUE )
+		})
+		names( res ) <- xandy
+	} else{
+		res <- list()
 	}
-	# Add xonly items
-	if (length(xonly) > 0) {
-	 	for (i in 1:length(xonly)){
-			item <- xonly[i]
-			res[[ item ]] <- x[[ item ]]
-		}
+	
+	if( length(xonly)>0 ){
+		res[ xonly ] <- x[ xonly ]
 	}
-	# Add yonly items
-	if (length(yonly) > 0) {
-	 	for (i in 1:length(yonly)){
-	 		item <- yonly[i]
-			res[[ item ]] <- y[[ item ]]
-		}
+	if( length(yonly)>0 ){
+		res[ yonly ] <- y[ yonly ]
 	}
-	return(res)
+	res
 }
 # }}}
 



More information about the Zooimage-commits mailing list