]> git.donarmstrong.com Git - ape.git/blobdiff - R/rTrait.R
various bug fixes
[ape.git] / R / rTrait.R
index 2c18d0940af08ada1fcaf1a67c8cba9b5402b1ed..6731c5cf94526939a767158e9d2f5cebf3bf0174 100644 (file)
@@ -1,4 +1,4 @@
-## rTrait.R (2011-04-02)
+## rTrait.R (2011-06-16)
 
 ##   Trait Evolution
 
@@ -135,7 +135,7 @@ rTraitCont <-
 
 rTraitMult <-
     function(phy, model, p = 1, root.value = rep(0, p), ancestor = FALSE,
-             as.factor = NULL, ...)
+             asFactor = NULL, trait.labels = paste("x", 1:p, sep = ""), ...)
 {
     phy <- reorder(phy, "pruningwise")
     n <- length(phy$tip.label)
@@ -152,6 +152,8 @@ rTraitMult <-
     el <- phy$edge.length
     if (is.null(el)) el <- numeric(N)
 
+    environment(model) <- environment() # to find 'p'
+
     for (i in N:1) x[des[i], ] <- model(x[anc[i], ], el[i], ...)
 
     if (ancestor) {
@@ -162,8 +164,9 @@ rTraitMult <-
         rownames(x) <- phy$tip.label
     }
     x <- as.data.frame(x)
-    if (!is.null(as.factor)) {
-        for (i in as.factor) {
+    names(x) <- trait.labels
+    if (!is.null(asFactor)) {
+        for (i in asFactor) {
             y <- x[, i]
             x[, i] <- factor(y, labels = LETTERS[1:length(unique(y))])
         }