[Phylobase-commits] r684 - in pkg: R inst/unitTests man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 30 02:39:41 CEST 2009


Author: regetz
Date: 2009-09-30 02:39:40 +0200 (Wed, 30 Sep 2009)
New Revision: 684

Modified:
   pkg/R/formatData.R
   pkg/inst/unitTests/runit.formatData.R
   pkg/man/addData.Rd
   pkg/man/formatData.Rd
   pkg/man/phylo4d.Rd
   pkg/man/tdata.Rd
Log:
changed formatData to handle data supplied as factors or matrices;
updated docs to be more general about this, and added simple tests


Modified: pkg/R/formatData.R
===================================================================
--- pkg/R/formatData.R	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/R/formatData.R	2009-09-30 00:39:40 UTC (rev 684)
@@ -18,13 +18,13 @@
         return(data.frame(row.names=ids.out))
     }
     ## if vector, coerce to data.frame
-    if (is.vector(dt)) {
+    if (is.vector(dt) || is.factor(dt) || is.matrix(dt)) {
         dt <- as.data.frame(dt)
     }
     ## before proceeding, make sure that data provided are a data frame
     if (!is.data.frame(dt)) {
-        nmSomeData <- substitute(dt)
-        stop(paste(nmSomeData, "must be a vector or a data frame"))
+        stop(paste(deparse(substitute(dt)),
+            "must be a vector, factor, matrix, or data frame"))
     }
     ## if lacking rows or columns, return a placeholder data frame with
     ## node numbers as row names

Modified: pkg/inst/unitTests/runit.formatData.R
===================================================================
--- pkg/inst/unitTests/runit.formatData.R	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/inst/unitTests/runit.formatData.R	2009-09-30 00:39:40 UTC (rev 684)
@@ -48,6 +48,25 @@
     #   missing.data=c("fail", "warn", "OK"),
     #   extra.data=c("warn", "OK", "fail"), keep.all=TRUE
 
+    ## vector data coerced to data.frame (colname dt)
+    checkIdentical(formatData(phy.alt, 1:5),
+        formatData(phy.alt, data.frame(dt=1:5)))
+    ## list of vector data coerced to data.frame (colnames as given)
+    checkIdentical(formatData(phy.alt, list(a=1:5, b=6:10)),
+        formatData(phy.alt, data.frame(a=1:5, b=6:10)))
+    ## factor data coerced to data.frame (colname dt)
+    checkIdentical(formatData(phy.alt, factor(letters[1:5])),
+        formatData(phy.alt, data.frame(dt=letters[1:5])))
+    ## matrix data coerced to data.frame (colnames V1, V2)
+    checkIdentical(formatData(phy.alt, matrix(1:10, ncol=2)),
+        formatData(phy.alt, data.frame(V1=1:5, V2=6:10)))
+    ## matrix data coerced to data.frame (colname as given)
+    checkIdentical(formatData(phy.alt, matrix(1:10, ncol=2,
+        dimnames=list(NULL, c("a", "b")))),
+        formatData(phy.alt, data.frame(a=1:5, b=6:10)))
+    ## error if dt is, say, a phylo4 object
+    checkException(formatData(phy.alt, phy.alt))
+
     #
     # matching options
     #

Modified: pkg/man/addData.Rd
===================================================================
--- pkg/man/addData.Rd	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/man/addData.Rd	2009-09-30 00:39:40 UTC (rev 684)
@@ -17,9 +17,12 @@
 }
 \arguments{
   \item{x}{a phylo4 or a phylo4d object}
-  \item{tip.data}{a data frame for tip data}
-  \item{node.data}{a data frame for node data}
-  \item{all.data}{a data frame for both tip an node data}
+  \item{tip.data}{a data frame (or object to be coerced to one)
+    containing only tip data}
+  \item{node.data}{a data frame (or object to be coerced to one)
+    containing only node data}
+  \item{all.data}{a data frame (or object to be coerced to one)
+    containing both tip and node data}
   \item{match.data}{(logical), should the row names provided in
     \code{tip.data}, \code{node.data} and/or \code{all.data} be used to
     match data against the tree labels?}

Modified: pkg/man/formatData.Rd
===================================================================
--- pkg/man/formatData.Rd	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/man/formatData.Rd	2009-09-30 00:39:40 UTC (rev 684)
@@ -18,7 +18,7 @@
 
 \arguments{
   \item{phy}{a valid \code{phylo4} object}
-  \item{dt}{a data frame or a vector}
+  \item{dt}{a data frame, matrix, vector, or factor}
   \item{type}{type of data to attach}
   \item{match.data}{(logical) Are data labels matched against tree
     labels?} 

Modified: pkg/man/phylo4d.Rd
===================================================================
--- pkg/man/phylo4d.Rd	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/man/phylo4d.Rd	2009-09-30 00:39:40 UTC (rev 684)
@@ -36,10 +36,12 @@
 \arguments{
   \item{x}{an object of class \code{phylo4}, \code{phylo} or a matrix of
   edges (see above)}
-  \item{tip.data}{a data frame for tips data}
-  \item{node.data}{a data frame for nodes data}
-  \item{all.data}{a data frame for all (i.e. tips and nodes) data. In such
-    case, first rows should correspond to tips, last rows to nodes.}
+  \item{tip.data}{a data frame (or object to be coerced to one)
+    containing only tip data}
+  \item{node.data}{a data frame (or object to be coerced to one)
+    containing only node data}
+  \item{all.data}{a data frame (or object to be coerced to one)
+    containing both tip and node data}
   \item{match.data}{(logical) should the rownames of the data frame
     provided in \code{tip.data}, \code{node.data} and/or \code{all.data}
     be used to be matched against tip and internal node identifiers? See

Modified: pkg/man/tdata.Rd
===================================================================
--- pkg/man/tdata.Rd	2009-09-29 23:44:29 UTC (rev 683)
+++ pkg/man/tdata.Rd	2009-09-30 00:39:40 UTC (rev 684)
@@ -37,8 +37,9 @@
       \code{phylo4d} (e.g. \code{match.data}), see \link{phylo4d} for
       more details.}
 
-    \item{value}{a data frame to replace the values associated with the
-      nodes specified by the argument \code{type}}
+    \item{value}{a data frame (or object to be coerced to one) to
+      replace the values associated with the nodes specified by the
+      argument \code{type}}
 
 }
 



More information about the Phylobase-commits mailing list