run_chain = function(tree_init, max_iter = 100, propose_tree = TreeSearch::NNI, seed = 0) {
set.seed(seed)
trees = list()
tree = tree_init
for (i in 1:max_iter) {
message(i)
trees[[i]] = tree
tree = propose_tree(tree)
}
class(trees) = 'multiPhylo'
return(trees)
}
set.seed(0)
ntips = 4
tree_init = rtree(ntips)
trees = run_chain(tree_init, max_iter = 16, propose_tree = phangorn::rSPR)
1
2
3
Error in oneOf4(tree, ind[2], ind[1], sample(c(1, 2), 1), sample(c(1, : trees must be binary
Traceback:
1. propose_tree(tree)
2. kSPR(trees, k = k)
3. oneOf4(tree, ind[2], ind[1], sample(c(1, 2), 1), sample(c(1,
. 2), 1), root)
4. stop("trees must be binary")
5. .handleSimpleError(function (cnd)
. {
. watcher$capture_plot_and_output()
. cnd <- sanitize_call(cnd)
. watcher$push(cnd)
. switch(on_error, continue = invokeRestart("eval_continue"),
. stop = invokeRestart("eval_stop"), error = invokeRestart("eval_error",
. cnd))
. }, "trees must be binary", base::quote(oneOf4(tree, ind[2], ind[1],
. sample(c(1, 2), 1), sample(c(1, 2), 1), root)))
Reproducible example:
output: