X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fnj.R;h=dada70e52a2a63b20777f98a6bee4ecfab65320e;hb=821974300c3d4c88584832e3f4b2c99ed56601cb;hp=c99bce3306aed82dbe0ba85ab54f3d5a28174040;hpb=c827059eeafc8cbe41c812b26979543ab287803e;p=ape.git diff --git a/R/nj.R b/R/nj.R index c99bce3..dada70e 100644 --- a/R/nj.R +++ b/R/nj.R @@ -1,8 +1,8 @@ -## nj.R (2006-09-15) +## nj.R (2009-11-23) ## Neighbor-Joining Tree Estimation -## Copyright 2004-2006 Emmanuel Paradis +## Copyright 2004-2009 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -10,16 +10,16 @@ nj <- function(X) { if (is.matrix(X)) X <- as.dist(X) + if (any(is.na(X))) + stop("missing values are not allowed in the distance matrix") N <- attr(X, "Size") labels <- attr(X, "Labels") if (is.null(labels)) labels <- as.character(1:N) - edge1 <- edge2 <- integer(2*N - 3) - edge.length <- numeric(2*N - 3) - ans <- .C("nj", as.double(X), as.integer(N), as.integer(edge1), - as.integer(edge2), as.double(edge.length), PACKAGE = "ape") - obj <- list(edge = cbind(ans[[3]], ans[[4]]), - edge.length = ans[[5]], tip.label = labels) - obj$Nnode <- N - 2 + ans <- .C("nj", as.double(X), as.integer(N), integer(2*N - 3), + integer(2*N - 3), double(2*N - 3), + DUP = FALSE, NAOK = TRUE, PACKAGE = "ape") + obj <- list(edge = cbind(ans[[3]], ans[[4]]), edge.length = ans[[5]], + tip.label = labels, Nnode = N - 2L) class(obj) <- "phylo" reorder(obj) }