Skip to content

Commit

Permalink
Improve write.tree. digits < 0 prints no branch lengths. Add digits a…
Browse files Browse the repository at this point in the history
…rgument to write.nexus.
  • Loading branch information
KlausVigo committed Oct 8, 2024
1 parent 5c14a70 commit 3df2eee
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/write.nexus.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.

write.nexus <- function(..., file = "", translate = TRUE)
write.nexus <- function(..., file = "", translate = TRUE, digits=10)
{
obj <- .getTreesFromDotdotdot(...)
ntree <- length(obj)
Expand Down Expand Up @@ -59,7 +59,7 @@ write.nexus <- function(..., file = "", translate = TRUE)
if (!inherits(obj[[i]], "phylo")) next
root.tag <- if (is.rooted(obj[[i]])) "= [&R] " else "= [&U] "
cat("\tTREE *", title[i], root.tag, file = file, append = TRUE)
cat(write.tree(obj[[i]], file = ""),
cat(write.tree(obj[[i]], file = "", digits=digits),
"\n", sep = "", file = file, append = TRUE)
}
cat("END;\n", file = file, append = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/write.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ write.tree <-

.write.tree2 <- function(phy, digits = 10, tree.prefix = "", check_tips)
{
brl <- !is.null(phy$edge.length)
brl <- (!is.null(phy$edge.length) && digits >= 0)
nodelab <- !is.null(phy$node.label)
if (check_tips) phy$tip.label <- checkLabel(phy$tip.label)
if (nodelab) {
Expand Down
4 changes: 3 additions & 1 deletion man/write.nexus.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\alias{write.nexus}
\title{Write Tree File in Nexus Format}
\usage{
write.nexus(..., file = "", translate = TRUE)
write.nexus(..., file = "", translate = TRUE, digits=10)
}
\arguments{
\item{\dots}{either (i) a single object of class \code{"phylo"}, (ii) a
Expand All @@ -14,6 +14,8 @@ write.nexus(..., file = "", translate = TRUE)
\item{translate}{a logical, if \code{TRUE} (the default) a translation
of the tip labels is done which are replaced in the parenthetic
representation with tokens.}
\item{digits}{a numeric giving the number of digits used for printing
branch lengths. For negative numbers no branch lengths are printed.}
}
\description{
This function writes trees in a file with the NEXUS format.
Expand Down
4 changes: 2 additions & 2 deletions man/write.tree.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ write.tree(phy, file = "", append = FALSE,
without erasing the data possibly existing in the file, otherwise
the file (if it exists) is overwritten (\code{FALSE} the default).}
\item{digits}{a numeric giving the number of digits used for printing
branch lengths.}
branch lengths. For negative numbers no branch lengths are printed.}
\item{tree.names}{either a logical or a vector of mode character. If
\code{TRUE} then any tree names will be written prior to the tree on
each line. If character, specifies the name of \code{"phylo"}
Expand Down Expand Up @@ -54,7 +54,7 @@ write.tree(phy, file = "", append = FALSE,

\author{Emmanuel Paradis, Daniel Lawson
\email{dan.lawson@bristol.ac.uk}, and Klaus Schliep
\email{kschliep@snv.jussieu.fr}}
\email{klaus.schliep@gmail.com}}
\seealso{
\code{\link{read.tree}}, \code{\link{read.nexus}},
\code{\link{write.nexus}}, \code{\link{write.phyloXML}}
Expand Down

0 comments on commit 3df2eee

Please sign in to comment.