Fix a bug in child() by heavywatal · Pull Request #8 · YuLab-SMU/tidytree (original) (raw)
The old version fails when .data$label
contains numeric characters like '6'
because isTRUE('6' == 6)
in R, and it causes superfluous match.
Now .node
argument must be always numeric and compared with .data$parent
.
library(tidytree) library(ape) set.seed(2017) tree = rtree(4) x = as_tibble(tree) y = x %>% dplyr::mutate(label = as.character(sample.int(length(node)))) child(y, 6)
Output from the current version:
Warning in .data$parent == .node :
longer object length is not a multiple of shorter object length
Calls: child -> child.tbl_tree -> which
Empty data.table (0 rows) of 4 cols: parent,node,branch.length,label
Output from the fixed version:
parent node branch.length label
<int> <int> <num> <char>
1: 6 3 0.6743315 6
2: 6 7 0.4349056 7