[Zooimage-commits] r99 - pkg/zooimage/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Apr 21 11:55:15 CEST 2009
Author: romain
Date: 2009-04-21 11:55:15 +0200 (Tue, 21 Apr 2009)
New Revision: 99
Modified:
pkg/zooimage/R/ZIRes.r
pkg/zooimage/R/utilities.r
Log:
factoring out getSample
Modified: pkg/zooimage/R/ZIRes.r
===================================================================
--- pkg/zooimage/R/ZIRes.r 2009-04-21 09:46:06 UTC (rev 98)
+++ pkg/zooimage/R/ZIRes.r 2009-04-21 09:55:15 UTC (rev 99)
@@ -151,9 +151,7 @@
# Extract only data for a given sample
# Sample is everything before a '+' sign
- Smps <- sub("[+].*", "", as.character(ZIDat$Label))
- mustcontain( unique(Smps), sample,
- msg = paste( "sample '", sample, "' is not in ZIDat", sep = "" ) )
+ Smps <- getSample( ZIDat$Label, unique = TRUE, must.have = sample )
Smp <- ZIDat[Smps == sample, ]
# Determine the number of images in this sample
@@ -228,10 +226,9 @@
mustbeString( sample, 1 )
# Extract only data for a given sample
- Smps <- sub("[+].*", "", as.character(ZIDat$Label)) # Sample is everything before a '+' sign
- mustcontain( unique(Smps), sample,
- msg = paste("sample '", sample, "' is not in ZIDat") )
+ Smps <- getSample( ZIDat$Label, unique = T, must.have = sample )
Smp <- ZIDat[Smps == sample, ]
+
# Subsample, depending on taxa we keep
if (!is.null(taxa)) {
mustcontain( levels(Smp$Ident), taxa, "taxa not in the sample")
@@ -325,10 +322,7 @@
type <- match.arg( type, several.ok = FALSE )
# Extract only data for a given sample
- Smps <- sub("[+].*", "", as.character(ZIDat$Label)) # Sample is everything before a '+' sign
- if (!sample %in% unique(Smps)){
- stop("sample '", sample, "' is not in ZIDat")
- }
+ Smps <- getSample( ZIDat$Label, unique = T, must.have = sample )
Smp <- ZIDat[Smps == sample, ]
# Subsample, depending on taxa we keep
Modified: pkg/zooimage/R/utilities.r
===================================================================
--- pkg/zooimage/R/utilities.r 2009-04-21 09:46:06 UTC (rev 98)
+++ pkg/zooimage/R/utilities.r 2009-04-21 09:55:15 UTC (rev 99)
@@ -440,6 +440,23 @@
}
# }}}
+getSample <- function( x, unique = FALSE, must.have, msg){
+ res <- sub("[+].*", "", as.character(x))
+ if( unique ){
+ res <- unique( res )
+ }
+ if( !missing(must.have) ){
+ if( ! all( must.have %in% res ) ){
+ if( missing(msg) ){
+ msg <- sprintf( "sample '%s' not in ZIDat", paste(must.have, sep = ",") )
+ }
+ stop( msg )
+ }
+ }
+ res
+}
+
+
# {{{ Internationalization of ZooImage: get messages in other languages
"gettextZI" <- function(...) {
### TODO: internationalization of the package
More information about the Zooimage-commits
mailing list