[Phylobase-commits] r489 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 19 01:39:34 CEST 2009


Author: skembel
Date: 2009-08-19 01:39:33 +0200 (Wed, 19 Aug 2009)
New Revision: 489

Modified:
   pkg/R/setAs-Methods.R
Log:
Update setAs method to work properly for unrooted phylo4 -> phylo conversion

Modified: pkg/R/setAs-Methods.R
===================================================================
--- pkg/R/setAs-Methods.R	2009-08-18 23:24:53 UTC (rev 488)
+++ pkg/R/setAs-Methods.R	2009-08-18 23:39:33 UTC (rev 489)
@@ -85,15 +85,20 @@
     if (inherits(from, "phylo4d"))
         warning("losing data while coercing phylo4d to phylo")
     brlen0 <- brlen <- unname(from at edge.length)
-    ## rootnode is only node with no ancestor
-    rootpos <- which(is.na(from at edge[, 1]))
-    if (isRooted(from)) brlen <- brlen[-rootpos]
+    if (isRooted(from)) {
+        ## rootnode is only node with no ancestor
+        rootpos <- which(is.na(from at edge[, 1]))    
+        brlen <- brlen[-rootpos]
+        edgemat <- unname(from at edge[-rootpos, ])    
+      } else {
+        edgemat <- from at edge
+    }
     if(hasNodeLabels(from)) {
         nodLbl <- unname(from at node.label)
-      }  else {
+      } else {
         nodLbl <- character(0)
-      }
-    edgemat <- unname(from at edge[-rootpos, ])
+    }
+
     y <- list(edge = edgemat,
               edge.length = brlen,
               tip.label = unname(from at tip.label),



More information about the Phylobase-commits mailing list