-## read.nexus.R (2008-09-17)
+## read.nexus.R (2009-04-01)
## Read Tree File in Nexus Format
-## Copyright 2003-2008 Emmanuel Paradis
+## Copyright 2003-2009 Emmanuel Paradis
## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.
tree <- X[start:end]
rm(X)
tree <- gsub("^.*= *", "", tree)
+ ## check whether there are empty lines from the above manips:
+ tree <- tree[tree != ""]
semico <- grep(";", tree)
Ntree <- length(semico)
## are some trees on several lines?
STRING <- character(Ntree)
s <- c(1, semico[-Ntree] + 1)
j <- mapply(":", s, semico)
- for (i in 1:Ntree)
- STRING[i] <- paste(tree[j[, i]], collapse = "")
+ if (is.list(j)) {
+ for (i in 1:Ntree)
+ STRING[i] <- paste(tree[j[[i]]], collapse = "")
+ } else {
+ for (i in 1:Ntree)
+ STRING[i] <- paste(tree[j[, i]], collapse = "")
+ }
} else STRING <- tree
}
rm(tree)
class(trees) <- "multiPhylo"
}
if (length(grep("[\\/]", file)) == 1)
- file <- paste(getwd(), file, sep = "/")
+ if (!file.exists(file)) # suggestion by Francois Michonneau
+ file <- paste(getwd(), file, sep = "/")
attr(trees, "origin") <- file
trees
}