From noreply at r-forge.r-project.org Thu Nov 5 15:02:12 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 5 Nov 2015 15:02:12 +0100 (CET) Subject: [Vegan-commits] r2973 - pkg/vegan/R Message-ID: <20151105140212.8E867187C61@r-forge.r-project.org> Author: jarioksa Date: 2015-11-05 15:02:11 +0100 (Thu, 05 Nov 2015) New Revision: 2973 Modified: pkg/vegan/R/vegdist.R Log: Merge branch 'cran-2.3' into r-forge-svn-local Modified: pkg/vegan/R/vegdist.R =================================================================== --- pkg/vegan/R/vegdist.R 2015-10-23 09:33:00 UTC (rev 2972) +++ pkg/vegan/R/vegdist.R 2015-11-05 14:02:11 UTC (rev 2973) @@ -15,10 +15,10 @@ stop("invalid distance method") if (method == -1) stop("ambiguous distance method") - if (method > 2 && any(rowSums(x, na.rm = TRUE) == 0)) + if (!method %in% c(1,2,6,16) && any(rowSums(x, na.rm = TRUE) == 0)) warning("you have empty rows: their dissimilarities may be meaningless in method ", dQuote(inm)) - if (method > 2 && any(x < 0, na.rm = TRUE)) + if (!method %in% c(1,2,6,16) && any(x < 0, na.rm = TRUE)) warning("results may be meaningless because data have negative entries in method ", dQuote(inm)) if (method == 11 && any(colSums(x) == 0)) From noreply at r-forge.r-project.org Fri Nov 13 08:21:48 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 13 Nov 2015 08:21:48 +0100 (CET) Subject: [Vegan-commits] r2974 - pkg/vegan/R Message-ID: <20151113072148.D087F186D3D@r-forge.r-project.org> Author: jarioksa Date: 2015-11-13 08:21:48 +0100 (Fri, 13 Nov 2015) New Revision: 2974 Modified: pkg/vegan/R/howHead.R Log: Squashed commit of the following: commit 8587c83f846a91221a6cc9d24a533029e18425a0 Author: Gavin L. Simpson Date: Thu Nov 12 16:09:43 2015 -0600 fix a bug in determining the numbers of rows and columns in a within-plot grid design (cherry picked from commit 2fa990a8e23cfb0c56800155dac9c99127745218) Modified: pkg/vegan/R/howHead.R =================================================================== --- pkg/vegan/R/howHead.R 2015-11-05 14:02:11 UTC (rev 2973) +++ pkg/vegan/R/howHead.R 2015-11-13 07:21:48 UTC (rev 2974) @@ -39,8 +39,8 @@ head <- paste0(head, " constant permutation within each Plot") } if (isTRUE(all.equal(type, "grid"))) { - nr <- getRow(x, which = "plots") - nc <- getCol(x, which = "plots") + nr <- getRow(x, which = "within") + nc <- getCol(x, which = "within") head <- paste0(head, sprintf(ngettext(nr, " %d row", " %d rows"), nr)) head <- paste0(head, sprintf(ngettext(nc, " %d column", From noreply at r-forge.r-project.org Fri Nov 13 10:32:55 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 13 Nov 2015 10:32:55 +0100 (CET) Subject: [Vegan-commits] r2975 - www Message-ID: <20151113093256.0DF14187CFC@r-forge.r-project.org> Author: jarioksa Date: 2015-11-13 10:32:55 +0100 (Fri, 13 Nov 2015) New Revision: 2975 Modified: www/NEWS.html Log: NEWS about 2.3-2 Modified: www/NEWS.html =================================================================== --- www/NEWS.html 2015-11-13 07:21:48 UTC (rev 2974) +++ www/NEWS.html 2015-11-13 09:32:55 UTC (rev 2975) @@ -7,6 +7,51 @@

vegan News

+

Changes in version 2.3-2

+ + + +

BUG FIXES

+ + + + + + + +

NEW FEATURES

+ + + + + + +

Changes in version 2.3-1

From noreply at r-forge.r-project.org Fri Nov 13 13:05:33 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 13 Nov 2015 13:05:33 +0100 (CET) Subject: [Vegan-commits] r2976 - pkg/vegan/inst Message-ID: <20151113120533.E906D184BCD@r-forge.r-project.org> Author: jarioksa Date: 2015-11-13 13:05:33 +0100 (Fri, 13 Nov 2015) New Revision: 2976 Modified: pkg/vegan/inst/NEWS.Rd Log: Squashed commit of the following: commit 7024df2c2de9e54c23c97dc91b87b6d9b750b2b1 Author: Jari Oksanen Date: Fri Nov 13 11:50:12 2015 +0200 stop commit 05da200d6df320d37e9ccf93b33f12004e1394ef Author: Jari Oksanen Date: Fri Nov 13 11:44:15 2015 +0200 add ref to issue #144 in NEWS commit 899bdb761317144fe616b00490111b6d8d4d1cf5 Author: Jari Oksanen Date: Fri Nov 13 11:30:48 2015 +0200 we probably have 2.3-2: write NEWS commit 8587c83f846a91221a6cc9d24a533029e18425a0 Author: Gavin L. Simpson Date: Thu Nov 12 16:09:43 2015 -0600 fix a bug in determining the numbers of rows and columns in a within-plot grid design (cherry picked from commit 2fa990a8e23cfb0c56800155dac9c99127745218) Modified: pkg/vegan/inst/NEWS.Rd =================================================================== --- pkg/vegan/inst/NEWS.Rd 2015-11-13 09:32:55 UTC (rev 2975) +++ pkg/vegan/inst/NEWS.Rd 2015-11-13 12:05:33 UTC (rev 2976) @@ -2,6 +2,43 @@ \title{vegan News} \encoding{UTF-8} +\section{Changes in version 2.3-2}{ + + \subsection{BUG FIXES}{ + \itemize{ + + \item Display of gridded permutation results failed. + + \item \code{ordicluster} joined the branches at wrong coordinates + in some cases. + + \item \code{ordiellipse} ignored weights when calculating standard + errors (\code{kind = "se"}). This influenced plots of \code{cca}, + and also influenced \code{ordiareatest}. + + } % itemize + } % bug fixes + + \subsection{NEW FEATURES}{ + \itemize{ + + \item \code{text}, \code{points} and \code{lines} functions for + \code{procrustes} analysis gained new argument \code{truemean} + which allows adding \code{procrustes} items to the plots of + original analysis. + + \item \code{rrarefy} returns observed non-rarefied communities + (with a warning) when users request subsamples that are larger + than the observed community instead of failing. Function + \code{drarefy} has been similar and returned sampling + probabilities of 1, but now it also issues a warning. Fixes issue + \href{https://github.com/vegandevs/vegan/issues/144}{#144} in + Github. + + } % itemize + } % new features +} %v2.3-2 + \section{Changes in version 2.3-1}{ \subsection{BUG FIXES}{ From noreply at r-forge.r-project.org Fri Nov 13 13:07:01 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 13 Nov 2015 13:07:01 +0100 (CET) Subject: [Vegan-commits] r2977 - www Message-ID: <20151113120701.2F919184BCD@r-forge.r-project.org> Author: jarioksa Date: 2015-11-13 13:07:00 +0100 (Fri, 13 Nov 2015) New Revision: 2977 Modified: www/NEWS.html Log: update NEWS Modified: www/NEWS.html =================================================================== --- www/NEWS.html 2015-11-13 12:05:33 UTC (rev 2976) +++ www/NEWS.html 2015-11-13 12:07:00 UTC (rev 2977) @@ -45,7 +45,9 @@ (with a warning) when users request subsamples that are larger than the observed community instead of failing. Function drarefy has been similar and returned sampling -probabilities of 1, but now it also issues a warning. +probabilities of 1, but now it also issues a warning. Fixes issue +#144 in +Github.

From noreply at r-forge.r-project.org Thu Nov 19 09:21:24 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Nov 2015 09:21:24 +0100 (CET) Subject: [Vegan-commits] r2978 - in pkg/vegan: . R inst man Message-ID: <20151119082125.130EB187060@r-forge.r-project.org> Author: jarioksa Date: 2015-11-19 09:21:24 +0100 (Thu, 19 Nov 2015) New Revision: 2978 Modified: pkg/vegan/DESCRIPTION pkg/vegan/R/adonis.R pkg/vegan/R/capscale.R pkg/vegan/R/mso.R pkg/vegan/inst/NEWS.Rd pkg/vegan/man/clamtest.Rd pkg/vegan/man/mso.Rd Log: Merge branch 'cran-2.3' into r-forge-svn-local Modified: pkg/vegan/DESCRIPTION =================================================================== --- pkg/vegan/DESCRIPTION 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/DESCRIPTION 2015-11-19 08:21:24 UTC (rev 2978) @@ -1,7 +1,7 @@ Package: vegan Title: Community Ecology Package Version: 2.3-2 -Date: 2015-09-25 +Date: 2015-11-19 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, Peter R. Minchin, R. B. O'Hara, Gavin L. Simpson, Peter Solymos, M. Henry H. Stevens, Helene Wagner Modified: pkg/vegan/R/adonis.R =================================================================== --- pkg/vegan/R/adonis.R 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/R/adonis.R 2015-11-19 08:21:24 UTC (rev 2978) @@ -38,8 +38,11 @@ if (any(lhs < -TOL)) stop("dissimilarities must be non-negative") dmat <- as.matrix(lhs^2) - } - else { + } else if ((is.matrix(lhs) || is.data.frame(lhs)) && + isSymmetric(unname(as.matrix(lhs)))) { + dmat <- as.matrix(lhs^2) + lhs <- as.dist(lhs) # crazy: need not to calculate beta.sites + } else { dist.lhs <- as.matrix(vegdist(lhs, method=method, ...)) dmat <- dist.lhs^2 } Modified: pkg/vegan/R/capscale.R =================================================================== --- pkg/vegan/R/capscale.R 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/R/capscale.R 2015-11-19 08:21:24 UTC (rev 2978) @@ -18,6 +18,10 @@ ## mysteriously at this point. X <- eval(formula[[2]], envir=environment(formula), enclos = globalenv()) + ## see if user supplied dissimilarities as a matrix + if ((is.matrix(X) || is.data.frame(X)) && + isSymmetric(unname(as.matrix(X)))) + X <- as.dist(X) if (!inherits(X, "dist")) { comm <- X dfun <- match.fun(dfun) Modified: pkg/vegan/R/mso.R =================================================================== --- pkg/vegan/R/mso.R 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/R/mso.R 2015-11-19 08:21:24 UTC (rev 2978) @@ -12,7 +12,14 @@ N <- nrow(object$CA$Xbar) if (inherits(object, "rda")) N <- 1 - Dist <- dist(xy) + ## we expect xy are coordinates and calculate distances, but a + ## swift user may have supplied distances, and we use them. + ## However, we won't test for distances in square matrices, but + ## treat that as a user mistake and let it go. + if (inherits(xy, "dist")) + Dist <- xy + else + Dist <- dist(xy) object$grain <- grain if (round.up) H <- ceiling(Dist/grain) * grain Modified: pkg/vegan/inst/NEWS.Rd =================================================================== --- pkg/vegan/inst/NEWS.Rd 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/inst/NEWS.Rd 2015-11-19 08:21:24 UTC (rev 2978) @@ -7,7 +7,8 @@ \subsection{BUG FIXES}{ \itemize{ - \item Display of gridded permutation results failed. + \item Printing details of a gridded permutation design would fail + when the grid was at the within-plot level. \item \code{ordicluster} joined the branches at wrong coordinates in some cases. @@ -22,6 +23,17 @@ \subsection{NEW FEATURES}{ \itemize{ + \item \code{adonis} and \code{capscale} functions recognize + symmetric square matrices as dissimilarities. Formerly + dissimilarities had to be given as \code{"dist"} objects such as + produced by \code{dist} or \code{vegdist} functions, and data + frames and matrices were regarded as observations x variables + data which could confuse users (e.g., issue + \href{https://github.com/vegandevs/vegan/issues/147}{#147}). + + \item \code{mso} accepts \code{"dist"} objects for the distances + among locations as an alternative to coordinates of locations. + \item \code{text}, \code{points} and \code{lines} functions for \code{procrustes} analysis gained new argument \code{truemean} which allows adding \code{procrustes} items to the plots of Modified: pkg/vegan/man/clamtest.Rd =================================================================== --- pkg/vegan/man/clamtest.Rd 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/man/clamtest.Rd 2015-11-19 08:21:24 UTC (rev 2978) @@ -114,7 +114,7 @@ } \note{ The code was tested against standalone CLAM software provided -on the website of Anne Chao (\url{http://chao.stat.nthu.edu.tw/softwarece.html}); +on the website of Anne Chao (\url{http://chao.stat.nthu.edu.tw/wordpress/}); minor inconsistencies were found, especially for finding the threshold for 'too rare' species. These inconsistencies are probably due to numerical differences between the Modified: pkg/vegan/man/mso.Rd =================================================================== --- pkg/vegan/man/mso.Rd 2015-11-13 12:07:00 UTC (rev 2977) +++ pkg/vegan/man/mso.Rd 2015-11-19 08:21:24 UTC (rev 2978) @@ -18,12 +18,13 @@ } \arguments{ \item{object.cca}{ An object of class cca, created by the \code{\link{cca}} or - \code{\link{rda}} function.} - \item{object.xy}{ A vector, matrix or data frame with the spatial - coordinates of the data represented by object.cca. Must have the - same number of rows as \code{object.cca$CA$Xbar} (see - \code{\link{cca.object}}). } - \item{grain}{ Interval size for distance classes.} + \code{\link{rda}} function.} + \item{object.xy}{ A vector, matrix or data frame with the spatial + coordinates of the data represented by \code{object.cca}. The + number of rows must match the number of observations (as given by + \code{nobs}) in \code{cca.object}. Alternatively, interpoint + distances can be supplied as a \code{\link{dist}} object. } + \item{grain}{ Interval size for distance classes.} \item{round.up}{ Determines the choice of breaks. If false, distances are rounded to the nearest multiple of grain. If true, distances are rounded to the upper multiple of grain.} From noreply at r-forge.r-project.org Thu Nov 19 09:27:00 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Nov 2015 09:27:00 +0100 (CET) Subject: [Vegan-commits] r2979 - www Message-ID: <20151119082701.04190186F23@r-forge.r-project.org> Author: jarioksa Date: 2015-11-19 09:27:00 +0100 (Thu, 19 Nov 2015) New Revision: 2979 Modified: www/NEWS.html Log: update NEWS Modified: www/NEWS.html =================================================================== --- www/NEWS.html 2015-11-19 08:21:24 UTC (rev 2978) +++ www/NEWS.html 2015-11-19 08:27:00 UTC (rev 2979) @@ -15,7 +15,8 @@
    -
  • Display of gridded permutation results failed. +

  • Printing details of a gridded permutation design would fail +when the grid was at the within-plot level.

  • ordicluster joined the branches at wrong coordinates @@ -35,6 +36,19 @@

      +
    • adonis and capscale functions recognize +symmetric square matrices as dissimilarities. Formerly +dissimilarities had to be given as "dist" objects such as +produced by dist or vegdist functions, and data +frames and matrices were regarded as observations x variables +data which could confuse users (e.g., issue +#147). +

      +
    • +
    • mso accepts "dist" objects for the distances +among locations as an alternative to coordinates of locations. +

      +
    • text, points and lines functions for procrustes analysis gained new argument truemean which allows adding procrustes items to the plots of From noreply at r-forge.r-project.org Thu Nov 26 10:14:59 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 26 Nov 2015 10:14:59 +0100 (CET) Subject: [Vegan-commits] r2980 - in pkg/vegan: . R Message-ID: <20151126091459.78165186E88@r-forge.r-project.org> Author: jarioksa Date: 2015-11-26 10:14:58 +0100 (Thu, 26 Nov 2015) New Revision: 2980 Modified: pkg/vegan/DESCRIPTION pkg/vegan/R/anosim.R pkg/vegan/R/bioenv.default.R pkg/vegan/R/gdispweight.R pkg/vegan/R/mrpp.R pkg/vegan/R/rarefy.R Log: Squashed commit of the following: commit 43e0233943ef8c6f56b6f1a716beb13a3b32ecfc Author: Jari Oksanen Date: Wed Nov 25 13:14:35 2015 +0200 rarefy gave false warnings if data was a vector or dropped to vector also improved ordering of tests for warnings and errors (cherry picked from commit 223ec5fbfa800318428f689d2be7da89ef5d4316) commit b73869871ed2ec227527c528e127ea5b42a4018d Author: Jari Oksanen Date: Wed Nov 25 12:11:30 2015 +0200 community data cannot be a matrix, but it must be a data.frame (cherry picked from commit cd45945e36c2d5c6273b05910e95211e0a88f1d9) commit 42738f74db28ffccd6000253ec10f490233bc779 Author: Jari Oksanen Date: Thu Nov 19 19:54:39 2015 +0200 cleaner test for symmetric matrices that also works for data frames (cherry picked from commit c10762873165c108e9591b1f0e38fbd5af13a87c) commit c35d409d072f04dfd201f4cebaa0f83fc3c16f80 Author: Jari Oksanen Date: Thu Nov 19 19:35:37 2015 +0200 cleaner test for distances in symmetric matrices or data frames earlier failed with data.frames (cherry picked from commit dc815de504391a344264320cecfff0dfd6cabb84) commit 4f5e2bb57baf3638cd7e9ce49199cc08898740a2 Author: Jari Oksanen Date: Thu Nov 19 19:29:55 2015 +0200 clean and correct test for distances in symmetric matrices as.dist() was not done after successful test for symmetric matrices and analysis failed later when it assumed data are no dist objects. (cherry picked from commit 96bb628b9833980d4d1b7bbb8ea33c6870c43283) commit 670c79d5fe9f5101be4ec0b73fee2a4856e54d12 Author: Jari Oksanen Date: Thu Nov 26 10:58:41 2015 +0200 vegan 2.3-2 was released: update version version 2.3-3 may never be released, but head on towards 2.4-0. However, changes must go to a new number just in case. Modified: pkg/vegan/DESCRIPTION =================================================================== --- pkg/vegan/DESCRIPTION 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/DESCRIPTION 2015-11-26 09:14:58 UTC (rev 2980) @@ -1,7 +1,7 @@ Package: vegan Title: Community Ecology Package -Version: 2.3-2 -Date: 2015-11-19 +Version: 2.3-3 +Date: 2015-11-26 Author: Jari Oksanen, F. Guillaume Blanchet, Roeland Kindt, Pierre Legendre, Peter R. Minchin, R. B. O'Hara, Gavin L. Simpson, Peter Solymos, M. Henry H. Stevens, Helene Wagner Modified: pkg/vegan/R/anosim.R =================================================================== --- pkg/vegan/R/anosim.R 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/R/anosim.R 2015-11-26 09:14:58 UTC (rev 2980) @@ -5,12 +5,13 @@ EPS <- sqrt(.Machine$double.eps) if (inherits(dat, "dist")) x <- dat - else if (is.matrix(dat) && nrow(dat) == ncol(dat) && all(dat[lower.tri(dat)] == - t(dat)[lower.tri(dat)])) { - x <- dat + else if ((is.matrix(dat) || is.data.frame(dat)) && + isSymmetric(unname(as.matrix(dat)))) { + x <- as.dist(dat) attr(x, "method") <- "user supplied square matrix" } - else x <- vegdist(dat, method = distance) + else + x <- vegdist(dat, method = distance) if (any(x < -sqrt(.Machine$double.eps))) warning("some dissimilarities are negative -- is this intentional?") sol <- c(call = match.call()) Modified: pkg/vegan/R/bioenv.default.R =================================================================== --- pkg/vegan/R/bioenv.default.R 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/R/bioenv.default.R 2015-11-26 09:14:58 UTC (rev 2980) @@ -70,8 +70,8 @@ index <- attr(comdis, "method") if (is.null(index)) index <- "unspecified" - } else if (is.matrix(comm) && nrow(comm) == ncol(comm) && - isTRUE(all.equal(comm, t(comm)))) { + } else if ((is.matrix(comm) || is.data.frame(comm)) && + isSymmetric(unname(as.matrix(comm)))) { comdis <- as.dist(comm) index <- "supplied square matrix" } else { Modified: pkg/vegan/R/gdispweight.R =================================================================== --- pkg/vegan/R/gdispweight.R 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/R/gdispweight.R 2015-11-26 09:14:58 UTC (rev 2980) @@ -26,6 +26,7 @@ family <- quasipoisson() V <- family$variance ## fit models to all species separately and extract results + comm <- as.data.frame(comm) mods <- lapply(comm, function(y) glm.fit(x, y, family = family)) y <- sapply(mods, '[[', "y") mu <- sapply(mods, fitted) Modified: pkg/vegan/R/mrpp.R =================================================================== --- pkg/vegan/R/mrpp.R 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/R/mrpp.R 2015-11-26 09:14:58 UTC (rev 2980) @@ -14,8 +14,8 @@ } if (inherits(dat, "dist")) dmat <- dat - else if (is.matrix(dat) && nrow(dat) == ncol(dat) && all(dat[lower.tri(dat)] == - t(dat)[lower.tri(dat)])) { + else if ((is.matrix(dat) || is.data.frame(dat)) && + isSymmetric(unname(as.matrix(dat)))) { dmat <- dat attr(dmat, "method") <- "user supplied square matrix" } Modified: pkg/vegan/R/rarefy.R =================================================================== --- pkg/vegan/R/rarefy.R 2015-11-19 08:27:00 UTC (rev 2979) +++ pkg/vegan/R/rarefy.R 2015-11-26 09:14:58 UTC (rev 2980) @@ -2,22 +2,23 @@ function (x, sample, se = FALSE, MARGIN = 1) { x <- as.matrix(x) - minsample <- min(apply(x, MARGIN, sum)) - if (any(sample > minsample)) - warning( - gettextf("Requested 'sample' was larger than smallest site maximum (%d)", - minsample)) ## as.matrix changes an n-vector to a n x 1 matrix if (ncol(x) == 1 && MARGIN == 1) x <- t(x) if (!identical(all.equal(x, round(x)), TRUE)) stop("function accepts only integers (counts)") + minsample <- min(apply(x, MARGIN, sum)) if (missing(sample)) { - sample <- min(apply(x, MARGIN, sum)) - info <- paste("The size of 'sample' must be given --\nHint: Smallest site maximum", - sample) - stop(info) + stop( + gettextf( + "The size of 'sample' must be given --\nHint: Smallest site maximum %d", + minsample)) } + if (any(sample > minsample)) + warning( + gettextf( + "Requested 'sample' was larger than smallest site maximum (%d)", + minsample)) rarefun <- function(x, sample) { x <- x[x > 0] J <- sum(x) From noreply at r-forge.r-project.org Mon Nov 30 08:46:30 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Nov 2015 08:46:30 +0100 (CET) Subject: [Vegan-commits] r2981 - pkg/vegan/R Message-ID: <20151130074631.048C2187AF9@r-forge.r-project.org> Author: jarioksa Date: 2015-11-30 08:46:30 +0100 (Mon, 30 Nov 2015) New Revision: 2981 Modified: pkg/vegan/R/treedist.R pkg/vegan/R/treedive.R pkg/vegan/R/treeheight.R Log: Merge branch 'cran-2.3' into r-forge-svn-local Modified: pkg/vegan/R/treedist.R =================================================================== --- pkg/vegan/R/treedist.R 2015-11-26 09:14:58 UTC (rev 2980) +++ pkg/vegan/R/treedist.R 2015-11-30 07:46:30 UTC (rev 2981) @@ -1,6 +1,11 @@ `treedist` <- function(x, tree, relative = TRUE, match.force = TRUE, ...) { + ## we cannot reconstruct tree with reversals from cophenetic + tree <- as.hclust(tree) + if (any(diff(tree$height) < -sqrt(.Machine$double.eps))) + stop("tree with reversals cannot be handled") + x <- as.matrix(x) n <- nrow(x) ABJ <- matrix(0, n , n) dmat <- as.matrix(cophenetic(tree)) Modified: pkg/vegan/R/treedive.R =================================================================== --- pkg/vegan/R/treedive.R 2015-11-26 09:14:58 UTC (rev 2980) +++ pkg/vegan/R/treedive.R 2015-11-30 07:46:30 UTC (rev 2981) @@ -1,8 +1,12 @@ `treedive` <- function(comm, tree, match.force = TRUE, verbose = TRUE) { + EPS <- sqrt(.Machine$double.eps) + comm <- as.matrix(comm) if (!inherits(tree, c("hclust", "spantree"))) - stop("'clus' must be an 'hclust' or 'spantree' result object") + stop("'tree' must be an 'hclust' or 'spantree' result object") + if (inherits(tree, "hclust") && any(diff(tree$height) < -EPS)) + stop("tree with reversals cannot be handled") m <- as.matrix(cophenetic(tree)) ## Check tree/comm match by names if (match.force || ncol(comm) != ncol(m)) { Modified: pkg/vegan/R/treeheight.R =================================================================== --- pkg/vegan/R/treeheight.R 2015-11-26 09:14:58 UTC (rev 2980) +++ pkg/vegan/R/treeheight.R 2015-11-30 07:46:30 UTC (rev 2981) @@ -4,6 +4,27 @@ if (inherits(tree, "spantree")) return(sum(tree$dist)) tree <- as.hclust(tree) - sum(tree$height) + max(tree$height) + ## nodes should start from 0 -- if there are negative heights, + ## tree is too pathological to be measured. + if (any(tree$height < 0)) + stop("negative heights: tree cannot be measured") + ## can be done really fast if there are no reversals, but we need + ## to traverse the tree with reversals + if (is.unsorted(tree$height)) { # slow + h <- tree$height + m <- tree$merge + height <- 0 + for (i in 1:nrow(m)) { + for (j in 1:2) { + if (m[i,j] < 0) + height <- height + h[i] + else + height <- height + abs(h[i] - h[m[i,j]]) + } + } + height + } + else # fast + sum(tree$height) + max(tree$height) }