[Phylobase-commits] r507 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 19 20:04:35 CEST 2009


Author: bbolker
Date: 2009-08-19 20:04:34 +0200 (Wed, 19 Aug 2009)
New Revision: 507

Modified:
   pkg/R/prune.R
Log:

 add .chnumsort (sort character in alphanumeric order) to fix bug #585 --
data scrambling on pruning



Modified: pkg/R/prune.R
===================================================================
--- pkg/R/prune.R	2009-08-19 16:46:13 UTC (rev 506)
+++ pkg/R/prune.R	2009-08-19 18:04:34 UTC (rev 507)
@@ -24,6 +24,11 @@
 }
 
 
+## return characters, sorted in NUMERIC order
+.chnumsort <- function(x) {
+  as.character(sort(as.numeric(x)))
+}
+
 setMethod("prune","phylo4",
           function(phy, tip, trim.internal = TRUE, subtree = FALSE,
                    ...) {
@@ -52,7 +57,7 @@
 
     if(!all(dim(phy at tip.data) == 0)) {
         tipDt <- phy at tip.data[match(tipToKeep, rownames(phy at tip.data)) ,, drop=FALSE]
-        tipDt <- tipDt[sort(rownames(tipDt)) ,, drop=FALSE]
+        tipDt <- tipDt[.chnumsort(rownames(tipDt)) ,, drop=FALSE]
         rownames(tipDt) <- 1:nTips(phytr)
     }
     else
@@ -60,7 +65,7 @@
 
     if(!all(dim(phy at node.data) == 0)) {
         nodDt <- phy at node.data[match(nodToKeep, rownames(phy at node.data)) ,, drop=FALSE]
-        nodDt <- nodDt[sort(rownames(nodDt)) ,, drop=FALSE]
+        nodDt <- nodDt[.chnumsort(rownames(nodDt)) ,, drop=FALSE]
         rownames(nodDt) <- 1:nNodes(phytr)
     }
     else



More information about the Phylobase-commits mailing list