[Phylobase-commits] r474 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 18 20:21:25 CEST 2009
Author: bbolker
Date: 2009-08-18 20:21:25 +0200 (Tue, 18 Aug 2009)
New Revision: 474
Modified:
pkg/R/readNexus.R
pkg/R/subset.R
pkg/R/treewalk.R
pkg/man/nNodes-methods.Rd
pkg/man/readNexus.Rd
pkg/man/treewalk.Rd
Log:
"which" hunt
Modified: pkg/R/readNexus.R
===================================================================
--- pkg/R/readNexus.R 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/R/readNexus.R 2009-08-18 18:21:25 UTC (rev 474)
@@ -1,7 +1,7 @@
-readNexus <- function (file, simplify=TRUE, which=c("all","tree","data"), char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=TRUE) {
+readNexus <- function (file, simplify=TRUE, type=c("all","tree","data"), char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=TRUE) {
#file = input nexus file
#simplify =
-#which = specify whether to return trees+data as phylo4d object ("all") if
+#type = specify whether to return trees+data as phylo4d object ("all") if
# both are found, returning a data.frame or phylo4 object if only one
# is found, "tree": return a phylo4 object only, regardless of
# whether there are data, "data": return a data.frame (no tree), even
@@ -12,7 +12,7 @@
#levels.uniform = if TRUE, categorical data are loaded with the same levels,
# even if one character is missing a state
output<-c("Failure")
- if (which=="all" || which=="data") {
+ if (type=="all" || type=="data") {
params <- list(filename=file, allchar=char.all, polymorphictomissing=polymorphic.convert, levelsall=levels.uniform)
# Check that params is properly formatted.
@@ -25,7 +25,7 @@
#print(incharsstring)
tipdata<-eval(parse(text=incharsstring))
}
- if (which=="all" || which=="tree") {
+ if (type=="all" || type=="tree") {
trees<-c("Failure");
params <- list(filename=file)
@@ -49,10 +49,10 @@
trees<-as(intreesphylolist[[1]], "phylo4");
}
}
- if (which=="tree" || length(tipdata) == 0 ) {
+ if (type=="tree" || length(tipdata) == 0 ) {
output<-trees;
}
- else if (which=="data") {
+ else if (type=="data") {
output<-tipdata
}
else {
Modified: pkg/R/subset.R
===================================================================
--- pkg/R/subset.R 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/R/subset.R 2009-08-18 18:21:25 UTC (rev 474)
@@ -78,7 +78,7 @@
#### data handling
## for now handle only tip data - assumes tip names are good row.names
- tab <- tdata(x, which="tip")[i, j, ..., drop=FALSE]
+ tab <- tdata(x, type="tip")[i, j, ..., drop=FALSE]
#### tree handling
tip.include <- match(row.names(tab), x at tip.label)
Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/R/treewalk.R 2009-08-18 18:21:25 UTC (rev 474)
@@ -62,11 +62,11 @@
}
## get descendants [recursively]
-descendants <- function (phy, node, which=c("tips","children","all"))
+descendants <- function (phy, node, type=c("tips","children","all"))
{
## FIXME: allow vector of nodes? (or just let people lapply?)
- which <- match.arg(which)
- if (which=="children") return(children(phy,node))
+ type <- match.arg(type)
+ if (type=="children") return(children(phy,node))
node <- getNode(phy,node)
if (is.na(node)) stop("node ",node," not found in tree")
n <- nTips(phy)
@@ -76,9 +76,9 @@
for (j in d) {
if (j <= n)
l <- c(l,j)
- else if (which=="all") l <- c(l,j,
- descendants(phy,j,which="all"))
- else l <- c(l, descendants(phy,j,which=which))
+ else if (type=="all") l <- c(l,j,
+ descendants(phy,j,type="all"))
+ else l <- c(l, descendants(phy,j,type=type))
}
return(getNode(phy,l))
}
@@ -90,10 +90,10 @@
}
## get ancestors (all nodes)
-ancestors <- function (phy, node, which=c("all","parent","ALL"))
+ancestors <- function (phy, node, type=c("all","parent","ALL"))
{
- which <- match.arg(which)
- if (which=="parent") return(ancestor(phy,node))
+ type <- match.arg(type)
+ if (type=="parent") return(ancestor(phy,node))
oNode <- node <- getNode(phy,node)
if (is.na(node)) stop("node ",node," not found in tree")
res <- numeric(0)
@@ -108,7 +108,7 @@
node <- anc
if (anc==n+1) break
}
- if(which == "ALL") res <- c(oNode, res)
+ if(type == "ALL") res <- c(oNode, res)
return(getNode(phy,res))
}
@@ -139,7 +139,7 @@
return(res)
}
else {
- ancests <- lapply(nodes, ancestors, phy=phy, which="ALL")
+ ancests <- lapply(nodes, ancestors, phy=phy, type="ALL")
res <- getNode(phy, max(Reduce(intersect, ancests)))
return(res)
}
@@ -165,11 +165,11 @@
## main computations
comAnc <- MRCA(x, t1, t2) # common ancestor
- desComAnc <- descendants(x, comAnc, which="all")
- ancT1 <- ancestors(x, t1, which="all")
+ desComAnc <- descendants(x, comAnc, type="all")
+ ancT1 <- ancestors(x, t1, type="all")
path1 <- intersect(desComAnc, ancT1) # path: common anc -> t1
- ancT2 <- ancestors(x, t2, which="all")
+ ancT2 <- ancestors(x, t2, type="all")
path2 <- intersect(desComAnc, ancT2) # path: common anc -> t2
res <- union(path1, path2) # union of the path
Modified: pkg/man/nNodes-methods.Rd
===================================================================
--- pkg/man/nNodes-methods.Rd 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/man/nNodes-methods.Rd 2009-08-18 18:21:25 UTC (rev 474)
@@ -110,15 +110,15 @@
}
}
\usage{
- \S4method{tdata}{phylo4d}(x, which = "tip", \dots)
+ \S4method{tdata}{phylo4d}(x, type = "tip", \dots)
% what a pain: see
% https://stat.ethz.ch/pipermail/r-devel/2008-May/049653.html
- \S4method{tdata}{phylo4d}(object, which = "tip", \dots) <- value
- \S4method{edgeLength}{phylo4}(x, which)
+ \S4method{tdata}{phylo4d}(object, type = "tip", \dots) <- value
+ \S4method{edgeLength}{phylo4}(x, type)
\S4method{edges}{phylo4}(x, order, drop.root=FALSE, \dots)
}
\arguments{
- \item{which}{(tdata) which data to extract: "tip" (tips only), "node"
+ \item{type}{(tdata) which data to extract: "tip" (tips only), "node"
(internal nodes only), "allnode" (tips and internal nodes), "edge"
(edges) (edgeLength) which edge lengths to extract (indexed by
descendant node)}
Modified: pkg/man/readNexus.Rd
===================================================================
--- pkg/man/readNexus.Rd 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/man/readNexus.Rd 2009-08-18 18:21:25 UTC (rev 474)
@@ -12,12 +12,12 @@
}
}
\usage{
-readNexus(file, simplify=TRUE, which=c("all","tree","data"), char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=TRUE)
+readNexus(file, simplify=TRUE, type=c("all","tree","data"), char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=TRUE)
}
\arguments{
\item{file}{a Nexus file}
\item{simplify}{If FALSE, returns a list. If TRUE, returns a list if there are multiple trees, a single object otherwise}
- \item{which}{Determines which objects to return, if present}
+ \item{type}{Determines which type of objects to return, if present}
\item{char.all}{If TRUE, returns all characters, even those excluded in the NEXUS file}
\item{polymorphic.convert}{If TRUE, converts polymorphic DNA characters to missing data}
\item{levels.uniform}{If TRUE, uses the same levels for all characters}
Modified: pkg/man/treewalk.Rd
===================================================================
--- pkg/man/treewalk.Rd 2009-08-18 18:20:27 UTC (rev 473)
+++ pkg/man/treewalk.Rd 2009-08-18 18:21:25 UTC (rev 474)
@@ -19,11 +19,11 @@
}
\usage{
getNode(phy,node,missing=c("warn","OK","fail"))
-ancestors(phy, node, which=c("all","parent","ALL"))
+ancestors(phy, node, type=c("all","parent","ALL"))
ancestor(phy, node)
siblings(phy,node,include.self=FALSE)
children(phy, node)
-descendants(phy, node, which=c("tips","children","all"))
+descendants(phy, node, type=c("tips","children","all"))
MRCA(phy,\dots)
shortestPath(phy, node1, node2)
\S4method{sumEdgeLength}{phylo4}(phy, node)
@@ -33,7 +33,7 @@
\linkS4class{phylo4}, e.g. a \linkS4class{phylo4d} object)
}
\item{node}{a node ID number (or name)}
- \item{which}{(\code{ancestors}) specify whether to return just direct
+ \item{type}{(\code{ancestors}) specify whether to return just direct
ancestor ("parent"), all ancestor nodes ("all"), or all ancestor
nodes including self ("ALL"); (\code{descendants})
specify whether to return
@@ -56,8 +56,8 @@
returns a named vector of edge numbers}
\item{\code{ancestors} and \code{descendants}}{
return named vectors of the ancestors and descendants of a node; \code{ancestor} is a synonym
- for \code{ancestors(\dots, which="parent")} (i.e. direct ancestor only), while \code{children}
- is a synonym for \code{descendants(\dots, which="children")} (i.e. direct descendants only)}
+ for \code{ancestors(\dots, type="parent")} (i.e. direct ancestor only), while \code{children}
+ is a synonym for \code{descendants(\dots, type="children")} (i.e. direct descendants only)}
\item{\code{siblings}}{
returns sibling nodes (children of the same parent)}
\item{\code{mrca}}{
@@ -80,8 +80,8 @@
getNode(geospiza,"D")
ancestor(geospiza,"E")
children(geospiza,"C")
- descendants(geospiza,"D",which="tips")
- descendants(geospiza,"D",which="all")
+ descendants(geospiza,"D",type="tips")
+ descendants(geospiza,"D",type="all")
ancestors(geospiza,"D")
MRCA(geospiza,"conirostris","difficilis","fuliginosa")
MRCA(geospiza,"olivacea","conirostris")
@@ -98,7 +98,7 @@
## if(require(ape)){ edgelabels() }
## branch length from a tip to the root
- sumEdgeLength(geospiza, ancestors(geospiza, "fortis", which="ALL"))
+ sumEdgeLength(geospiza, ancestors(geospiza, "fortis", type="ALL"))
}
\keyword{misc}
More information about the Phylobase-commits
mailing list