0

当我尝试将 tibble 转换为树(treedataphylo)对象时出现错误,即使 tibble 最初是由树生成的。参见示例:

library(ape, quietly = TRUE, warn.conflicts = FALSE)
library(tidytree, quietly = TRUE, warn.conflicts = FALSE)
library(treeio, quietly = TRUE, warn.conflicts = FALSE)
#> treeio v1.14.4  For help: https://yulab-smu.top/treedata-book/

set.seed(2017)
a <- rtree(4) %>% as_tibble() %>% as.data.frame()
#> Warning: Unknown or uninitialised column: `node`.
print(a)
#>   parent node branch.length label
#> 1      5    1   0.434905600    t4
#> 2      7    2   0.674331481    t1
#> 3      7    3   0.002020766    t3
#> 4      6    4   0.025093514    t2
#> 5      5    5            NA  <NA>
#> 6      5    6   0.472166386  <NA>
#> 7      6    7   0.273833123  <NA>

# ERROR ON BOTH
a %>% as.treedata()     #calls treeio:::as.treedata.data.frame which calls treeio:::as.phylo.tbl_df
#> Error in check_edgelist(x): Cannot find root. network is not a tree!
a %>% as.phylo()        #calls treeio:::as.phylo.data.frame which is equal to treeio:::as.phylo.tbl_df
#> Error in check_edgelist(x): Cannot find root. network is not a tree!

它要求 'unique(parents[!(parents %in% children)])' 返回一个非零向量,但这与根节点本身的性质相矛盾:

例如 tidytree:::rootnode.tbl_tree 将根定义为具有 parent==node 的节点

reprex 包(v1.0.0)于 2021-06-04 创建

会话信息
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.5 (2021-03-31)
#>  os       Ubuntu 20.04.2 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  C.UTF-8                     
#>  ctype    C.UTF-8                     
#>  tz       Etc/UTC                     
#>  date     2021-06-04                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  ape         * 5.5     2021-04-25 [1] CRAN (R 4.0.5)
#>  assertthat    0.2.1   2019-03-21 [2] CRAN (R 4.0.4)
#>  cli           2.3.1   2021-02-23 [2] CRAN (R 4.0.4)
#>  crayon        1.4.1   2021-02-08 [2] CRAN (R 4.0.4)
#>  DBI           1.1.1   2021-01-15 [2] CRAN (R 4.0.4)
#>  digest        0.6.27  2020-10-24 [2] CRAN (R 4.0.4)
#>  dplyr         1.0.5   2021-03-05 [2] CRAN (R 4.0.4)
#>  ellipsis      0.3.1   2020-05-15 [2] CRAN (R 4.0.4)
#>  evaluate      0.14    2019-05-28 [2] CRAN (R 4.0.4)
#>  fansi         0.4.2   2021-01-15 [2] CRAN (R 4.0.4)
#>  fs            1.5.0   2020-07-31 [2] CRAN (R 4.0.4)
#>  generics      0.1.0   2020-10-31 [2] CRAN (R 4.0.4)
#>  glue          1.4.2   2020-08-27 [2] CRAN (R 4.0.4)
#>  highr         0.8     2019-03-20 [2] CRAN (R 4.0.4)
#>  htmltools     0.5.1.1 2021-01-22 [2] CRAN (R 4.0.4)
#>  jsonlite      1.7.2   2020-12-09 [2] CRAN (R 4.0.4)
#>  knitr         1.31    2021-01-27 [2] CRAN (R 4.0.4)
#>  lattice       0.20-41 2020-04-02 [4] CRAN (R 4.0.0)
#>  lazyeval      0.2.2   2019-03-15 [2] CRAN (R 4.0.4)
#>  lifecycle     1.0.0   2021-02-15 [2] CRAN (R 4.0.4)
#>  magrittr      2.0.1   2020-11-17 [2] CRAN (R 4.0.4)
#>  nlme          3.1-152 2021-02-04 [4] CRAN (R 4.0.3)
#>  pillar        1.5.1   2021-03-05 [2] CRAN (R 4.0.4)
#>  pkgconfig     2.0.3   2019-09-22 [2] CRAN (R 4.0.4)
#>  purrr         0.3.4   2020-04-17 [2] CRAN (R 4.0.4)
#>  R6            2.5.0   2020-10-28 [2] CRAN (R 4.0.4)
#>  Rcpp          1.0.6   2021-01-15 [2] CRAN (R 4.0.4)
#>  reprex        1.0.0   2021-01-27 [2] CRAN (R 4.0.4)
#>  rlang         0.4.10  2020-12-30 [2] CRAN (R 4.0.4)
#>  rmarkdown     2.7     2021-02-19 [2] CRAN (R 4.0.4)
#>  rstudioapi    0.13    2020-11-12 [2] CRAN (R 4.0.4)
#>  sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 4.0.4)
#>  stringi       1.5.3   2020-09-09 [2] CRAN (R 4.0.4)
#>  stringr       1.4.0   2019-02-10 [2] CRAN (R 4.0.4)
#>  tibble        3.1.0   2021-02-25 [2] CRAN (R 4.0.4)
#>  tidyselect    1.1.0   2020-05-11 [2] CRAN (R 4.0.4)
#>  tidytree    * 0.3.4   2021-05-22 [1] CRAN (R 4.0.5)
#>  treeio      * 1.14.4  2021-04-26 [1] Bioconductor  
#>  utf8          1.2.1   2021-03-12 [2] CRAN (R 4.0.4)
#>  vctrs         0.3.7   2021-03-29 [2] CRAN (R 4.0.4)
#>  withr         2.4.1   2021-01-26 [2] CRAN (R 4.0.4)
#>  xfun          0.22    2021-03-11 [2] CRAN (R 4.0.4)
#>  yaml          2.2.1   2020-02-01 [2] CRAN (R 4.0.4)
#> 
#> [1] /home/edoardo/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
4

0 回答 0