[Phylobase-commits] r749 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Mar 11 23:29:06 CET 2010
Author: francois
Date: 2010-03-11 23:29:06 +0100 (Thu, 11 Mar 2010)
New Revision: 749
Modified:
pkg/R/readNexus.R
pkg/man/readNexus.Rd
Log:
updated readNexus: (1) fixes behavior of levels.uniform, (2) added option return.labels
Modified: pkg/R/readNexus.R
===================================================================
--- pkg/R/readNexus.R 2010-03-11 02:35:45 UTC (rev 748)
+++ pkg/R/readNexus.R 2010-03-11 22:29:06 UTC (rev 749)
@@ -1,7 +1,8 @@
readNexus <- function (file, simplify=FALSE, type=c("all", "tree", "data"),
char.all=FALSE, polymorphic.convert=TRUE,
levels.uniform=TRUE, quiet=TRUE,
- check.node.labels=c("keep", "drop", "asdata"), ...) {
+ check.node.labels=c("keep", "drop", "asdata"),
+ return.labels=TRUE, ...) {
## file = input nexus file
## simplify = if TRUE only keeps the first tree, if several trees are found in
@@ -16,6 +17,8 @@
## characters
## levels.uniform = if TRUE, categorical data are loaded with the same levels,
## even if one character is missing a state
+ ## return.labels = if TRUE, returns the names of the states instead of the
+ ## the internal codes
## quiet = if TRUE, returns the object without printing tree strings (printing
## makes readNexus very slow in the cases of very big trees)
## check.node.labels = how to deal with node labels, to be passed to phylo4d
@@ -28,16 +31,40 @@
if (type == "all" || type == "data") {
params <- list(filename=file, allchar=char.all,
polymorphictomissing=polymorphic.convert,
- levelsall=levels.uniform)
+ levelsall=levels.uniform,
+ returnlabels=return.labels)
## Check that params is properly formatted.
if(!is.list(params) || length(params) == 0) {
stop("The params parameter must be a non-empty list")
}
+ incharsstring <- .Call("ReadCharsWithNCL", params,
+ PACKAGE="phylobase")
+ ## Remove empty labels for factors
+ incharsstring$charstring <- gsub("\\\"\\\"", "", incharsstring$charstring)
+ incharsstring$charstring <- gsub(",+)", ")", incharsstring$charstring)
- incharsstring <- .Call("ReadCharsWithNCL",params,
- PACKAGE="phylobase")
+ ## For now, we can't deal with polymorphic characters and their labels
+ if (length(grep("\\{", incharsstring$charstring)) > 0 &&
+ return.labels) {
+ stop("At this stage, it's not possible to use the combination:",
+ "return.labels=TRUE for datasets that contain polymorphic",
+ "characters.")
+ }
+
+ ## Convert the string to data frame
tipdata <- eval(parse(text=incharsstring))
+
+ ## if levels.uniform=TRUE apply the same levels to all characters
+ if (levels.uniform && length(tipdata) > 0) {
+ allLevels <- character(0)
+ for (i in 1:ncol(tipdata)) {
+ allLevels <- union(allLevels, levels(tipdata[,i]))
+ }
+ for (i in 1:ncol(tipdata)) {
+ levels(tipdata[,i]) <- allLevels
+ }
+ }
}
if (type == "all" || type == "tree") {
trees <- c("Failure");
Modified: pkg/man/readNexus.Rd
===================================================================
--- pkg/man/readNexus.Rd 2010-03-11 02:35:45 UTC (rev 748)
+++ pkg/man/readNexus.Rd 2010-03-11 22:29:06 UTC (rev 749)
@@ -13,7 +13,7 @@
\usage{
readNexus(file, simplify=FALSE, type=c("all", "tree", "data"),
char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=TRUE,
-quiet=TRUE, check.node.labels=c("keep", "drop", "asdata"), ...)
+quiet=TRUE, check.node.labels=c("keep", "drop", "asdata"), return.labels=TRUE, ...)
}
\arguments{
\item{file}{a Nexus file}
@@ -31,7 +31,9 @@
process if the tree is big or there are many trees in the file.}
\item{check.node.labels}{Determines how the node labels in the Nexus
files should be treated in the phylo4 object, see Details for more
- information.}
+ information.}
+ \item{return.labels}{Determines whether state names (if TRUE) or state
+ codes should be returned.}
\item{\dots}{Additional arguments to be passed to phylo4 or phylo4d
constructor (see details)}
}
More information about the Phylobase-commits
mailing list