Last chance! 50% off unlimited learning
Sale ends in
read.tree(file = "", text = NULL, tree.names = NULL, skip = 0,
comment.char = "#", keep.multi = FALSE, ...)
file = ""
(the default) then the
tree is input on the keyboard, the entry being terminated with a
blank line.NULL
, meaning that the tree is read in a
file); if text
is not NULL
NULL
(the default), the trees are named "tree1"
,
"tree2"
, ...scan()
).scan()
).TRUE
and tree.names = NULL
then
single trees are returned in "multiPhylo"
format, with any
name that is present (see details). Default is FALSE
.scan()
."phylo"
with the following components:edge
.edge
."multiPhylo"
, and is a list of objects of class "phylo"
.
The name of each tree can be specified by tree.names
, or can be
read from the file (see details).file
allows to type directly the tree on
the keyboard (or possibly to copy from an editor and paste in R's
console) with, e.g., mytree <- read.tree()
.`read.tree' tries to represent correctly trees with a badly represented root edge (i.e. with an extra pair of parentheses). For instance, the tree "((A:1,B:1):10);" will be read like "(A:1,B:1):10;" but a warning message will be issued in the former case as this is apparently not a valid Newick format. If there are two root edges (e.g., "(((A:1,B:1):10):10);"), then the tree is not read and an error message is issued.
If there are any characters preceding the first "(" in a line then
this is assigned to the name. This is returned when a "multiPhylo"
object is returned and tree.names = NULL
.
Olsen, G. Interpretation of the "Newick's 8:45" tree format standard.
Paradis, E. (2008) Definition of Formats for Coding Phylogenetic Trees
in R.
Paradis, E. (2012) Analysis of Phylogenetics and Evolution with R (Second Edition). New York: Springer.
write.tree
, read.nexus
,
write.nexus
, scan
for the basic R
function to read data in a file### An extract from Sibley and Ahlquist (1990)
s <- "owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);"
cat(s, file = "ex.tre", sep = "")
tree.owls <- read.tree("ex.tre")
str(tree.owls)
tree.owls
tree.owls <- read.tree("ex.tre", keep.multi = TRUE)
tree.owls
names(tree.owls)
unlink("ex.tre") # delete the file "ex.tre"
### Only the first three species using the option `text'
TREE <- "((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3);"
TREE
tree.owls.bis <- read.tree(text = TREE)
str(tree.owls.bis)
tree.owls.bis
Run the code above in your browser using DataLab