3 \title{Read Tree File in Parenthetic Format}
5 read.tree(file = "", text = NULL, tree.names = NULL, skip = 0,
6 comment.char = "#", keep.multi = FALSE, ...)
9 \item{file}{a file name specified by either a variable of mode character,
10 or a double-quoted string; if \code{file = ""} (the default) then the
11 tree is input on the keyboard, the entry being terminated with a
13 \item{text}{alternatively, the name of a variable of mode character
14 which contains the tree(s) in parenthetic format. By default, this
15 is ignored (set to \code{NULL}, meaning that the tree is read in a
16 file); if \code{text} is not \code{NULL}, then the argument
17 \code{file} is ignored.}
18 \item{tree.names}{if there are several trees to be read, a vector of
19 mode character that gives names to the individual trees; if
20 \code{NULL} (the default), the trees are named \code{"tree1"},
22 \item{skip}{the number of lines of the input file to skip before
23 beginning to read data (this is passed directly to\code{ scan()}).}
24 \item{comment.char}{a single character, the remaining of the line
25 after this character is ignored (this is passed directly to
27 \item{keep.multi}{if \code{TRUE} and \code{tree.names = NULL} then
28 single trees are returned in \code{"multiPhylo"} format, with any
29 name that is present (see details). Default is \code{FALSE}.}
30 \item{\dots}{further arguments to be passed to \code{scan()}.}
33 This function reads a file which contains one or several trees in
34 parenthetic format known as the Newick or New Hampshire format.
37 The default option for \code{file} allows to type directly the tree on
38 the keyboard (or possibly to copy from an editor and paste in R's
39 console) with, e.g., \code{mytree <- read.tree()}.
41 `read.tree' tries to represent correctly trees with a badly
42 represented root edge (i.e. with an extra pair of parentheses). For
43 instance, the tree "((A:1,B:1):10);" will be read like "(A:1,B:1):10;"
44 but a warning message will be issued in the former case as this is
45 apparently not a valid Newick format. If there are two root edges
46 (e.g., "(((A:1,B:1):10):10);"), then the tree is not read and an error
49 If there are any characters preceding the first "(" in a line then
50 this is assigned to the name. This is returned when a "multiphylo"
51 object is returned and \code{tree.names = NULL}.
54 an object of class \code{"phylo"} with the following components:
55 \item{edge}{a two-column matrix of mode numeric where each row
56 represents an edge of the tree; the nodes and the tips are
57 symbolized with numbers; the tips are numbered 1, 2, \dots, and the
58 nodes are numbered after the tips. For each row, the first column
60 \item{edge.length}{(optional) a numeric vector giving the lengths of the
61 branches given by \code{edge}.}
62 \item{tip.label}{a vector of mode character giving the names of the
63 tips; the order of the names in this vector corresponds to the
64 (positive) number in \code{edge}.}
65 \item{Nnode}{the number of (internal) nodes.}
66 \item{node.label}{(optional) a vector of mode character giving the
68 \item{root.edge}{(optional) a numeric value giving the length of the
69 branch at the root if it exists.}
71 If several trees are read in the file, the returned object is of class
72 \code{"multiPhylo"}, and is a list of objects of class \code{"phylo"}.
73 The name of each tree can be specified by \code{tree.names}, or can be
74 read from the file (see details).
77 Felsenstein, J. The Newick tree format.
78 \url{http://evolution.genetics.washington.edu/phylip/newicktree.html}
80 Olsen, G. Interpretation of the "Newick's 8:45" tree format standard.
81 \url{http://evolution.genetics.washington.edu/phylip/newick_doc.html}
83 Paradis, E. (2008) Definition of Formats for Coding Phylogenetic Trees
84 in R. \url{http://ape.mpl.ird.fr/misc/FormatTreeR_28July2008.pdf}
87 \author{Emmanuel Paradis \email{Emmanuel.Paradis@mpl.ird.fr} and Daniel
88 Lawson \email{dan.lawson@bristol.ac.uk}}
90 \code{\link{write.tree}}, \code{\link{read.nexus}},
91 \code{\link{write.nexus}}, \code{\link[base]{scan}} for the basic R
92 function to read data in a file
95 ### An extract from Sibley and Ahlquist (1990)
96 cat("owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);", file = "ex.tre", sep = "\n")
97 tree.owls <- read.tree("ex.tre")
100 tree.owls <- read.tree("ex.tre", keep.multi = TRUE)
103 unlink("ex.tre") # delete the file "ex.tre"
104 ### Only the first three species using the option `text'
105 TREE <- "((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3);"
107 tree.owls.bis <- read.tree(text = TREE)