R: Load a tree from a string or file in Newick (parenthetic)...

read_tree {castor} | R Documentation

## Load a tree from a string or file in Newick (parenthetic) format.

### Description

Load a phylogenetic tree from a file or a string, in Newick (parenthetic) format. Any valid Newick format is acceptable.

### Usage

    read_tree(  string  = "",
                file    = "",
                include_edge_lengths    = TRUE,
                include_node_labels     = TRUE,
                underscores_as_blanks   = FALSE,
                check_label_uniqueness  = FALSE)

### Arguments

`string` | A string containing a single tree in Newick format. Can be used alternatively to `file`.
`file` | A path to an input text file containing a single tree in Newick format. Can be used alternatively to `string`.
`include_edge_lengths` | Logical, specifying whether edge lengths (if available) should be included in the generated tree.
`include_node_labels` | Logical, specifying whether node labels (if available) should be included in the generated tree.
`underscores_as_blanks` | Logical, specifying whether underscores ("_") in tip and node labels should be replaced by spaces (" "). This is common behavior in other tree parsers. In any case, tip and node labels are also allowed to contain explicit whitespace (other than newlines).
`check_label_uniqueness` | Logical, specifying whether to check if all tip labels are unique.

### Details

This function is comparable to (but typically much faster than) the `ape` function `read.tree`. The function supports trees with monofurcations and multifurcations, trees with or without tip/node labels, and trees with or without edge lengths. The time complexity is linear in the number of edges in the tree.

Either `file` or `string` must be specified, but not both. The tree may be arbitrarily split across multiple lines, but no other non-whitespace text is permitted in `string` or in the input file. Flanking whitespace (space, tab, newlines) is ignored.

### Value

A single rooted phylogenetic tree in “phylo” format.

### Author(s)

Stilianos Louca

### See Also

`write_tree`

### Examples

    # generate a random tree
    tree = generate_random_tree(list(birth_rate_intercept=1),max_tips=100)$tree

    # obtain a string representation of the tree in Newick format
    Newick_string = write_tree(tree)

    # re-parse tree from string
    parsed_tree = read_tree(Newick_string)

[Package castor version 1.3.4 Index]