I think my issue is actually with future
and exporting methods rather than tidytree
, but if someone could explain to me what is actually happening and how I should be writing my code to avoid this problem it would be greatly appreciated.
I am using tidytree
to do some phylogenetic analyses. The function offspring
works fine when I use lapply
, but throws the following error when I use future_lapply
:
Error in UseMethod("offspring") :
no applicable method for 'offspring' applied to an object of class "phylo"
Reproducible example:
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))
And corresponding output:
> 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"