r语言 - 没有适用于类 "phylo" 对象的'offspring'方法



我认为我的问题实际上是future和导出方法,而不是tidytree,但如果有人能向我解释实际发生了什么,以及我应该如何编写代码来避免这个问题,我将不胜感激。

我正在使用tidytree进行一些系统发育分析。当我使用lapply时,函数offspring可以正常工作,但当我使用future_lapply时会抛出以下错误:

Error in UseMethod("offspring") : 
no applicable method for 'offspring' applied to an object of class "phylo"

可复制示例:

library(ape)
library(tidytree)
library(future.apply)
tree <- rtree(4)
lapply(5:7, function(x) offspring(tree,x, tiponly=TRUE))
future_lapply(5:7, function(x) tidytree::offspring(tree,x, tiponly=TRUE))

以及相应的输出:

> lapply(5:7, function(x) offspring(tree,x, tiponly=TRUE))
[[1]]
[1] 1 4 2 3
[[2]]
[1] 4 2 3
[[3]]
[1] 2 3
> future_lapply(5:7, function(x) tidytree::offspring(tree,x, tiponly=TRUE))
Error in UseMethod("offspring") : 
no applicable method for 'offspring' applied to an object of class "phylo"

我也可以使用lapply()重现此错误;

library(ape)
library(tidytree)
tree <- rtree(4)
y <- lapply(5:7, FUN = function(x) offspring(tree, x, tiponly = TRUE))
#> Error in UseMethod("offspring") : 
#>   no applicable method for 'offspring' applied to an object of class "phylo"

并且,也没有lapply()

library(ape)
library(tidytree)
tree <- rtree(4)
y <- offspring(tree, 5L, tiponly = TRUE)
#> Error in UseMethod("offspring") : 
#>  no applicable method for 'offspring' applied to an object of class "phylo"

发生这种情况是因为tree属于phylo:类

class(tree)
#> [1] "phylo"

但是tidytree没有为这个类提供任何S3方法;

methods("offspring")
#> [1] offspring.tbl_tree*
#> see '?methods' for accessing help and source code

看看?tidytree::offspring中的示例,您似乎忘记了:

tree <- as_tibble(tree)

添加使其工作,包括future.apply.

编辑:添加了解决方案。

最新更新