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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 21 09:57:28 CEST 2009


Author: romain
Date: 2009-04-21 09:57:25 +0200 (Tue, 21 Apr 2009)
New Revision: 91

Modified:
   pkg/zooimage/R/ZIRes.r
   pkg/zooimage/R/ZITrain.r
   pkg/zooimage/R/utilities.r
   pkg/zooimage/R/zid.r
   pkg/zooimage/R/zie.r
   pkg/zooimage/R/zim.r
   pkg/zooimage/R/zip.r
Log:
using ClearProgress

Modified: pkg/zooimage/R/ZIRes.r
===================================================================
--- pkg/zooimage/R/ZIRes.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/ZIRes.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -123,7 +123,7 @@
 			class(restot) <- c("ZI1Res", "ZIRes", "data.frame") 
 		}
 	}
-	Progress (imax + 1, imax)	 # To dismiss the Progress() indication
+	ClearProgress()
 	
 	# {{{ Final report
 	finish.loopfunction( ok = ok, show.log = show.log, bell = bell )

Modified: pkg/zooimage/R/ZITrain.r
===================================================================
--- pkg/zooimage/R/ZITrain.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/ZITrain.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -24,9 +24,8 @@
 	groups.template = c("[Basic]", "[Detailed]", "[Very detailed]"), 
 	ident = NULL, show.log = TRUE, bell = FALSE, start.viewer = FALSE) {
  	                       
-	# {{{ Make sure unzip is available
+	# Make sure unzip is available
 	checkCapable( "unzip" )
-	# }}}
 	
 	# First, check that dir is valid
 	checkDirExists( dir )
@@ -37,12 +36,10 @@
 	checkEmptyDir( dir , message = "must be empty. Clean it first!" )
 	
 	# Then, check that all zidfiles exist
-	if(!all(file.exists(zidfiles)) || !all( hasExtension(zidfiles, "zid")) ) {
-		stop( "One or more .zid files do not exist or is invalid!" )
-	}
+	checkAllFileExist( zidfiles, "zid" )
 
 	# Finally, look for the groups.template
-	groups.template <- groups.template[1]
+	groups.template <- match.arg( groups.template )
 	if (regexpr("^[[].+[]]$", groups.template) > 0) {
 		# This should be a template file in the default directory
 		groups.template <- paste(sub("^[[](.+)[]]$", "\\1", groups.template), ".zic", sep = "")
@@ -61,9 +58,8 @@
 		Progress(i, zmax)
 		unzip( zipfile = zidfiles[i] , path = dir, delete.source = FALSE )
 	}
-	Progress(i + 1, zmax)	# To dismiss the Progress() indication
+	ClearProgress()
 	
-	
 	# Create '_' subdir and unzip all vignettes there
 	dir_ <- file.path(dir, "_")
 	force.dir.create( dir_ )
@@ -79,7 +75,7 @@
 		unzip( zidfiles[i], path = dir_, delete.source = FALSE )
 		
 	}
-	Progress(i + 1, zmax)	# To dismiss the Progress() indication
+	ClearProgress()
 	
 	# Create the other directories
     Lines <- scan(groups.template, character(), sep = "\n", skip = 2, quiet = TRUE)
@@ -207,9 +203,8 @@
 	mustbe(ZIRecode, "ZIRecode")
 	
 	# Check that all levels in ZITrain$Class are represented in ZIRecode
-	if (!all(sort(levels(ZITrain$Class)) == sort(ZIRecode[ , 1]))) {
-		warnOrStop( "Not all levels of ZIRecode match levels of ZITrain" )
-	}
+	mustmatch( levels(ZITrain$Class), ZIRecode[ , 1], 
+		msg = "Not all levels of ZIRecode match levels of ZITrain" )
 	
 	# Class column of ZITrain is transformed into a character vector
 	clas <- as.character(ZITrain$Class)
@@ -217,8 +212,9 @@
 	
 	# It is then recoded
 	for (i in 1:nrow(ZIRecode)) {
-		if (ZIRecode[i, 1] != ZIRecode[i, 2])
+		if (ZIRecode[i, 1] != ZIRecode[i, 2]){
 			recoded[clas == ZIRecode[i, 1]] <- ZIRecode[i, 2]
+		}
 	}
 	
 	# ...and transformed back into a factor
@@ -228,7 +224,9 @@
 	# If a new path is given for these new groups, change it
 	path <- attr(ZIRecode, "path")
 	### TODO: check its validity here
-	if(!is.null(path)) attr(res, "path") <- path
+	if(!is.null(path)){
+		attr(res, "path") <- path
+	}
 	return(res)
 }
 # }}}

Modified: pkg/zooimage/R/utilities.r
===================================================================
--- pkg/zooimage/R/utilities.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/utilities.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -502,7 +502,7 @@
 	}
     invisible(NULL)
 }
-EraseProgress <- function( ){
+ClearProgress <- function( ){
 	Progress( 2, 1 )
 }
 # }}}
@@ -667,6 +667,16 @@
 	invisible( NULL )
 }
 
+
+checkAllFileExist <- function( files, extension){
+	if( !all( file.exists( files ) ) ){
+		stop( "one or more file does not exist" )
+	}
+	if( !missing(extension) && ! all( hasExtension( files, extension ) ) ){
+		stop( "one or more files have wrong extension" )
+	}
+}
+
 #' checks if a directory exists
 #'
 #' @param dir the directory to check
@@ -755,7 +765,7 @@
 }
 
 mustmatch <- function( x, y, msg ){
-	if( !all( x  == y ) ){
+	if( !all( sort( x )  == sort( y ) ) ){
 		if( missing(msg) ) msg <- sprintf( "'%s' and '%s' must match", deparse(substitute(x)), deparse(substitute(y)) )
 		stop( msg )
 	}

Modified: pkg/zooimage/R/zid.r
===================================================================
--- pkg/zooimage/R/zid.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/zid.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -426,7 +426,7 @@
 			}) 
 		
 	}
-	Progress (smax + 1, smax)	 # To dismiss the Progress() indication
+	ClearProgress()
 	# }}}
 	
 	# {{{ Possibly clean the whole directory (move .zim files to \_raw
@@ -578,8 +578,7 @@
 	# TODO: set the calling handlers in a way that ok is created
 	ok <- TRUE
 	
-	Progress (smax + 1, smax)	 # To dismiss the Progress() indication
-	
+	ClearProgress()
 	finish.loopfunction( ok, bell = bell, show.log = show.log )
 }
 # }}}

Modified: pkg/zooimage/R/zie.r
===================================================================
--- pkg/zooimage/R/zie.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/zie.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -301,7 +301,7 @@
 			allImages <- c(allImages, File)		
 		}
 	}
-	Progress (nLines + 1, nLines)	 # To dismiss the Progress() indication
+	ClearProgress()
 	logProcess("Checking all lines in the .zie file for raw images... OK!")
 	cat("...OK!\n")
 	# }}}
@@ -661,7 +661,7 @@
 	# }}}
 	
 	# {{{ cleans up
-	Progress (nLines + 1, nLines)	 # To dismiss the Progress() indication
+	ClearProgress()
 	# Possibly remove latest blank-field from root directory (not needed any more!)
 	if (!is.null(BlankField)) {
 		# Delete blank-field images (.pgm and .img) in the root directory

Modified: pkg/zooimage/R/zim.r
===================================================================
--- pkg/zooimage/R/zim.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/zim.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -64,9 +64,8 @@
 	}
 	# }}}
 	
-	Progress (zmax + 1, zmax)	 # To dismiss the Progress() indication
-	
 	# {{{ cleans up
+	ClearProgress()
 	finish.loopfunction( ok, bell = bell, show.log = show.log )
 	# }}}
 }
@@ -440,7 +439,7 @@
 					ok <<- FALSE
 				} )
 		}
-		Progress (zmax + 1, zmax)	 # To dismiss the Progress() indication
+		ClearProgress()
 	}
 	
 	if (ok) {
@@ -464,7 +463,7 @@
 			on.success = logProcess( "OK", zipfiles[i] ) )
 	
 	}
-	Progress (imax + 1, imax)	 # To dismiss the Progress() indication
+	ClearProgress()
 	# }}}
 	
 	# {{{ cleans up

Modified: pkg/zooimage/R/zip.r
===================================================================
--- pkg/zooimage/R/zip.r	2009-04-20 15:30:16 UTC (rev 90)
+++ pkg/zooimage/R/zip.r	2009-04-21 07:57:25 UTC (rev 91)
@@ -147,7 +147,7 @@
 				ok <- FALSE
 			}
 		}
-		Progress (zmax + 1, zmax)	 # To dismiss the progress() indication
+		ClearProgress()
 	}
 	if (ok) {
 		logProcess("\n-- OK, no error found. --")
@@ -180,7 +180,7 @@
 	}
 	#}}} 
 	
-	Progress (imax + 1, imax)	 # To dismiss the Progress() indication
+	ClearProgress()
 	
 	#{{{ Final report
 	finish.loopfunction( ok, bell = bell, show.log = show.log )



More information about the Zooimage-commits mailing list