`[<-.multiPhylo` does not support empty `[]`
ms609 opened this issue · comments
Martin R. Smith commented
The syntax myList[] <- X
typically allows entries of a list to be modified without overwriting attributes.
Compare:
myList <- structure(list(1, 2, 3, 4, 5), class = 'myClass')
class(myList) # "myClass"
myList[] <- sapply(myList, `*`, 2)
class(myList) # attributes retained
myList <- lapply(myList, `*`, 2)
class(myList) # attributes lost
However, the [<-.multiPhylo
function fails when a TipLabel
attribute is present and no parameter is passed, i.e.
trees <- c(read.tree(text = '(a, b, c);'), read.tree(text = '(a, b, c);'))
DoSomething <- function(tree) return(tree)
# This drops the multiPhylo class
bad <- lapply(trees, DoSomething)
# Keep multiPhylo class: This works okay
trees[] <- lapply(trees, DoSomething)
# But if trees have a TipLabels attribute, we fail:
attr(trees, 'TipLabel') <- c('a', 'b', 'c')
trees[] <- lapply(trees, DoSomething)
# Error in `[<-.multiPhylo`(`*tmp*`, , value = list(list(edge = c(4L, 4L, :
# argument "..1" is missing, with no default
Emmanuel Paradis commented
A fixed version is on GH. I did a few tests but more tests will be welcome.
Best,
Emmanuel