[R-gregmisc-users] SF.net SVN: r-gregmisc:[1774] trunk/gtools
Brought to you by:
warnes
From: <wa...@us...> - 2014-03-01 20:02:10
|
Revision: 1774 http://sourceforge.net/p/r-gregmisc/code/1774 Author: warnes Date: 2014-03-01 20:02:08 +0000 (Sat, 01 Mar 2014) Log Message: ----------- Fix bug in gtools::mixedorder regular expression for regognizing numbers. (Periods weren't escaped). Modified Paths: -------------- trunk/gtools/R/mixedsort.R Added Paths: ----------- trunk/gtools/tests/test_mixedorder.R Modified: trunk/gtools/R/mixedsort.R =================================================================== --- trunk/gtools/R/mixedsort.R 2014-02-11 17:44:04 UTC (rev 1773) +++ trunk/gtools/R/mixedsort.R 2014-03-01 20:02:08 UTC (rev 1774) @@ -17,7 +17,7 @@ if( is.numeric(x) ) return( order(x) ) - + delim="\\$\\@\\$" numeric <- function(x) @@ -37,7 +37,7 @@ if(length(which.blanks) >0) x[ which.blanks ] <- -Inf - + if(length(which.nas) >0) x[ which.nas ] <- Inf @@ -47,7 +47,7 @@ #### # find and mark numbers in the form of +1.23e+45.67 - delimited <- gsub("([+-]{0,1}[0-9]+.{0,1}[0-9]*([eE][\\+\\-]{0,1}[0-9]+.{0,1}[0-9]*){0,1})", + delimited <- gsub("([+-]{0,1}[0-9]+\\.{0,1}[0-9]*([eE][\\+\\-]{0,1}[0-9]+\\.{0,1}[0-9]*){0,1})", paste(delim,"\\1",delim,sep=""), x) # separate out numbers @@ -90,7 +90,7 @@ t(rank.character) + apply(matrix(rank.numeric),2,max,na.rm=TRUE) ) - + rank.overall <- ifelse(is.na(rank.character),rank.numeric,rank.character) order.frame <- as.data.frame(rank.overall) Added: trunk/gtools/tests/test_mixedorder.R =================================================================== --- trunk/gtools/tests/test_mixedorder.R (rev 0) +++ trunk/gtools/tests/test_mixedorder.R 2014-03-01 20:02:08 UTC (rev 1774) @@ -0,0 +1,27 @@ +library(gtools) + +## Examples from man page +Treatment <- c("Control", "Asprin 10mg/day", "Asprin 50mg/day", + "Asprin 100mg/day", "Acetomycin 100mg/day", + "Acetomycin 1000mg/day") + +stopifnot( mixedorder(tmp)==c(4, 5, 1, 2, 3 )) + + +x <- rev(c("AA 0.50 ml", "AA 1.5 ml", "AA 500 ml", "AA 1500 ml", + "EXP 1", "AA 1e3 ml", "A A A", "1 2 3 A", "NA", NA, "1e2", + "", "-", "1A", "1 A", "100", "100A", "Inf")) + +stopifnot( mixedorder(x)==c(7, 11, 4, 5, 3, 8, 2, 1, 6, 12, 18, 17, 16, 13, 15, 14, 10, 9) ) + +## Bug reported by Aaron Taudt on 2014-03-01 + +tmp <- c("uniresult_simulated_H3k27ac_binsize_200_chr1.RData", + "uniresult_simulated_H3k27me3_binsize_200_chr1.RData", + "uniresult_simulated_H3k36me3_binsize_200_chr1.RData", + "uniresult_simulated_H3k4me3_binsize_200_chr1.RData", + "uniresult_simulated_H3k9me3_binsize_200_chr1.RData") + +stopifnot( mixedorder(tmp)==c(4, 5, 1, 2, 3) ) + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |