2
#' Concatenate nexml files
4
#' Concatenate nexml files
5
#' @param x,... nexml objects to be concatenated, e.g. from
6
#' \code{\link{write.nexml}} or \code{\link{read.nexml}}.
7
#' Must have unique ids on all elements
8
#' @param recursive logical. If 'recursive = TRUE', the function recursively
9
#' descends through lists (and pairlists) combining all their
10
#' elements into a vector. (Not implemented).
11
#' @return a concatenated nexml file
14
#' f1 <- system.file("examples", "trees.xml", package="RNeXML")
15
#' f2 <- system.file("examples", "comp_analysis.xml", package="RNeXML")
16
#' nex1 <- read.nexml(f1)
17
#' nex2 <- read.nexml(f2)
18
#' nex <- c(nex1, nex2)
22
function(x, ..., recursive = FALSE){
23
elements = list(x, ...)
25
## Check that ids are unique
26
if(!do.call(unique_ids,elements))
27
stop("ids are not unique across nexml files.
28
Consider regenerating ids")
31
nexml@otus <- new("ListOfotus",
32
unlist(lapply(elements,
35
nexml@characters <- new("ListOfcharacters",
36
unlist(lapply(elements,
37
function(n) n@characters),
39
nexml@trees <- new("ListOftrees",
40
unlist(lapply(elements,
47
get_ids <- function(nexml){
48
doc <- xmlDoc(as(nexml, "XMLInternalNode"))
49
out <- unname(xpathSApply(doc, "//@id"))
54
unique_ids <- function(...){
56
counts <- table(unlist(lapply(set, get_ids)))