using the dplyr::mutate on tbl_tree convert it to tbl_df · Issue #7 · YuLab-SMU/tidytree (original) (raw)

Hi, applying mutate on tbl_tree remains no longer tbl_tree object . And therefore, cannot convert back to tree using as.phylo(). See the example below

tree <- rtree(4)
tree
Phylogenetic tree with 4 tips and 3 internal nodes.

Tip labels:
[1] "t1" "t4" "t3" "t2"

Rooted; includes branch lengths.

as_data_frame(tree) %>% class()
[1] "tbl_tree"   "tbl_df"     "tbl"        "data.frame"

as_data_frame(tree)  %>% dplyr::mutate(row_number()) %>% class()
[1] "tbl_df"     "tbl"        "data.frame"

tree_data <- as_data_frame(tree)  %>% dplyr::mutate(row_number())

as.phylo(tree_data)
Error in UseMethod("as.phylo") : 
  no applicable method for 'as.phylo' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"