Running examples in 'HiClimR-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: HiClimR
> ### Title: Hierarchical Climate Regionalization
> ### Aliases: HiClimR
> ### Keywords: HiClimR
> 
> ### ** Examples
> 
> require(HiClimR)
> 
> #----------------------------------------------------------------------------------#
> # Typical use of HiClimR for single-variate clustering:                            #
> #----------------------------------------------------------------------------------#
> 
> ## Load the test data included/loaded in the package (1 degree resolution)
> x <- TestCase$x
> lon <- TestCase$lon
> lat <- TestCase$lat
> 
> ## Generate/check longitude and latitude mesh vectors for gridded data
> xGrid <- grid2D(lon = unique(TestCase$lon), lat = unique(TestCase$lat))
> lon <- c(xGrid$lon)
> lat <- c(xGrid$lat)
> 
> ## Single-Variate Hierarchical Climate Regionalization
> y <- HiClimR(x, lon = lon, lat = lat, lonStep = 1, latStep = 1, geogMask = FALSE,
+     continent = "Africa", meanThresh = 10, varThresh = 0, detrend = TRUE,
+     standardize = TRUE, nPC = NULL, method = "ward", hybrid = FALSE, kH = NULL, 
+     members = NULL, nSplit = 1, upperTri = TRUE, verbose = TRUE, 
+     validClimR = TRUE, k = 12, minSize = 1, alpha = 0.01, 
+     plot = TRUE, colPalette = NULL, hang = -1, labels = FALSE)

PROCESSING STARTED

Checking Multivariate Clustering (MVC)...
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
HiClimR
 --- call from context --- 
HiClimR(x, lon = lon, lat = lat, lonStep = 1, latStep = 1, geogMask = FALSE, 
    continent = "Africa", meanThresh = 10, varThresh = 0, detrend = TRUE, 
    standardize = TRUE, nPC = NULL, method = "ward", hybrid = FALSE, 
    kH = NULL, members = NULL, nSplit = 1, upperTri = TRUE, verbose = TRUE, 
    validClimR = TRUE, k = 12, minSize = 1, alpha = 0.01, plot = TRUE, 
    colPalette = NULL, hang = -1, labels = FALSE)
 --- call from argument --- 
if (class(x) == "list") {
    if (verbose) 
        write("---> x is a list", "")
    nvars <- length(x)
    mm <- vector(mode = "numeric", length = nvars)
    if (nvars == 0) {
        stop("empty data list")
    }
    xx <- x[[1]]
    mm[1] <- dim(x[[1]])[2]
    if (nvars > 1) {
        if (length(meanThresh) != nvars || length(varThresh) != 
            nvars || length(detrend) != nvars || length(standardize) != 
            nvars || length(weightMVC) != nvars) {
            stop("meanThresh, varThresh, detrend, standardize and weightMVC length mismatch")
        }
        n1 <- dim(x[[1]])[1]
        for (nvar in 2:nvars) {
            if (dim(x[[nvar]])[1] != n1) {
                stop("matrices in x list should have the same number of rows!")
            }
            xx <- cbind(xx, x[[nvar]])
            mm[nvar] <- dim(x[[nvar]])[2]
        }
    }
    x <- xx
    rm(xx)
} else if (class(x) == "matrix") {
    if (verbose) 
        write("---> x is a matrix", "")
    mm <- dim(x)[2]
} else {
    if (verbose) 
        write("---> x should a matrix or a list of matrices", 
            "")
}
 --- R stacktrace ---
where 1: HiClimR(x, lon = lon, lat = lat, lonStep = 1, latStep = 1, geogMask = FALSE, 
    continent = "Africa", meanThresh = 10, varThresh = 0, detrend = TRUE, 
    standardize = TRUE, nPC = NULL, method = "ward", hybrid = FALSE, 
    kH = NULL, members = NULL, nSplit = 1, upperTri = TRUE, verbose = TRUE, 
    validClimR = TRUE, k = 12, minSize = 1, alpha = 0.01, plot = TRUE, 
    colPalette = NULL, hang = -1, labels = FALSE)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (x = list(), lon = NULL, lat = NULL, lonStep = 1, latStep = 1, 
    geogMask = FALSE, gMask = NULL, continent = NULL, region = NULL, 
    country = NULL, contigConst = 0, meanThresh = if (class(x) == 
        "list") vector("list", length(x)) else list(NULL), varThresh = if (class(x) == 
        "list") as.list(rep(0, length(x))) else list(0), detrend = if (class(x) == 
        "list") as.list(rep(FALSE, length(x))) else list(FALSE), 
    standardize = if (class(x) == "list") as.list(rep(FALSE, 
        length(x))) else list(FALSE), weightMVC = if (class(x) == 
        "list") as.list(rep(1, length(x))) else list(1), nPC = NULL, 
    method = "ward", hybrid = FALSE, kH = NULL, members = NULL, 
    nSplit = 1, upperTri = TRUE, verbose = TRUE, validClimR = TRUE, 
    rawStats = TRUE, k = NULL, minSize = 1, alpha = 0.05, plot = TRUE, 
    dendrogram = TRUE, colPalette = NULL, hang = -1, labels = FALSE, 
    pch = 15, cex = 1) 
{
    start.time.proc <- proc.time()
    start.time.sys <- Sys.time()
    if (verbose) 
        write("\nPROCESSING STARTED\n", "")
    if (verbose) 
        write("Checking Multivariate Clustering (MVC)...", "")
    nvars <- 1
    if (class(x) == "list") {
        if (verbose) 
            write("---> x is a list", "")
        nvars <- length(x)
        mm <- vector(mode = "numeric", length = nvars)
        if (nvars == 0) {
            stop("empty data list")
        }
        xx <- x[[1]]
        mm[1] <- dim(x[[1]])[2]
        if (nvars > 1) {
            if (length(meanThresh) != nvars || length(varThresh) != 
                nvars || length(detrend) != nvars || length(standardize) != 
                nvars || length(weightMVC) != nvars) {
                stop("meanThresh, varThresh, detrend, standardize and weightMVC length mismatch")
            }
            n1 <- dim(x[[1]])[1]
            for (nvar in 2:nvars) {
                if (dim(x[[nvar]])[1] != n1) {
                  stop("matrices in x list should have the same number of rows!")
                }
                xx <- cbind(xx, x[[nvar]])
                mm[nvar] <- dim(x[[nvar]])[2]
            }
        }
        x <- xx
        rm(xx)
    }
    else if (class(x) == "matrix") {
        if (verbose) 
            write("---> x is a matrix", "")
        mm <- dim(x)[2]
    }
    else {
        if (verbose) 
            write("---> x should a matrix or a list of matrices", 
                "")
    }
    if (verbose) {
        if (nvars == 1) {
            write("---> single-variate clustering: 1 variable", 
                "")
        }
        else {
            write(paste("---> multivariate clustering:", nvars, 
                "variables"), "")
        }
    }
    if (nvars > 1) {
        if (verbose) 
            write("Checking variable weights...", "")
        for (nvar in 1:nvars) {
            if (verbose) 
                write(paste("---> weight for variable #", nvar, 
                  ": ", weightMVC[[nvar]], sep = ""), "")
            if (!weightMVC[[nvar]] > 0) {
                stop("variable weights should be positive!")
            }
        }
    }
    else {
        weightMVC <- 1
    }
    if (lonStep > 1 && latStep > 1) {
        if (verbose) 
            write("Coarsening spatial resolution...", "")
        xc <- coarseR(x = x, lon = lon, lat = lat, lonStep = lonStep, 
            latStep = latStep, verbose = verbose)
    }
    else {
        xc <- coarseR(x = x, lon = lon, lat = lat, lonStep = 1, 
            latStep = 1, verbose = verbose)
    }
    lon <- xc$lon
    lat <- xc$lat
    x <- xc$x
    rm(xc)
    if (verbose) 
        write("Checking data...", "")
    if (verbose) 
        write("---> Checking dimensions...", "")
    n <- dim(x)[1]
    m <- dim(x)[2]
    if (is.null(n)) 
        stop("invalid data size")
    if (is.na(n)) 
        stop("size cannot be NA")
    if (n < 2) 
        stop("must have n <U+2265> 2 objects to cluster")
    if (verbose) 
        write("---> Checking row names...", "")
    if (is.null(rownames(x))) {
        rownames(x) <- seq(1, n)
    }
    if (verbose) 
        write("---> Checking column names...", "")
    if (is.null(colnames(x))) {
        colnames(x) <- seq(1, m)
    }
    mask <- NULL
    if (geogMask) {
        if (verbose) 
            write("Geographic masking...", "")
        if (is.null(gMask)) {
            gMask <- geogMask(continent = continent, region = region, 
                country = country, lon = lon, lat = lat, verbose = verbose, 
                plot = FALSE)
        }
        else {
            if (verbose) 
                write("---> Geographic mask is provided!", "")
        }
        if (length(gMask) > 0 && class(gMask) != "list") {
            if (min(gMask) >= 1 && max(gMask) <= n) {
                mask <- union(mask, as.integer(gMask))
            }
        }
    }
    mm0 <- 0
    xx <- x
    vv <- vector("list", nvars)
    if (verbose) 
        write("Data filtering...", "")
    for (nvar in 1:nvars) {
        if (nvars > 1) {
            if (verbose) 
                write(paste("---> VARIABLE #", nvar, ":", sep = ""), 
                  "")
        }
        m <- mm[nvar]
        x <- xx[, (mm0 + 1):(mm0 + m)]
        if (verbose) 
            write("---> Computing mean for each row...", "")
        xmean <- rowMeans(x)
        if (!is.null(meanThresh[[nvar]])) {
            if (verbose) 
                write("---> Checking rows with mean bellow meanThresh...", 
                  "")
            meanMask <- which(is.na(xmean) | xmean <= meanThresh[[nvar]])
            if (verbose) 
                write(paste("--->", length(meanMask), "rows found, mean <U+2264> ", 
                  meanThresh[[nvar]]), "")
            if (length(meanMask) > 0) {
                mask <- union(mask, meanMask)
            }
        }
        x <- x - xmean
        if (verbose) 
            write("---> Computing variance for each row...", 
                "")
        v <- rowSums(x^2, na.rm = TRUE)
        if (is.null(varThresh[[nvar]])) {
            varThresh[[nvar]] <- 0
        }
        varMask <- which(is.na(v) | v <= varThresh[[nvar]])
        if (verbose) 
            write("---> Checking rows with near-zero-variance...", 
                "")
        if (verbose) 
            write(paste("--->", length(varMask), "rows found, variance <U+2264> ", 
                varThresh[[nvar]]), "")
        if (length(varMask) > 0) {
            mask <- union(mask, varMask)
        }
        vv[[nvar]] <- v
        xx[, (mm0 + 1):(mm0 + m)] <- x
        mm0 <- mm0 + m
    }
    mm0 <- 0
    xxx <- NULL
    missVal <- list()
    if (verbose) 
        write("Data preprocessing...", "")
    for (nvar in 1:nvars) {
        if (nvars > 1) {
            if (verbose) 
                write(paste("---> VARIABLE #", nvar, ":", sep = ""), 
                  "")
        }
        m <- mm[nvar]
        v <- vv[[nvar]]
        x <- xx[, (mm0 + 1):(mm0 + m)]
        if (verbose) 
            write("---> Applying mask...", "")
        if (length(mask) > 0) {
            x <- x[-mask, ]
            v <- v[-mask]
        }
        if (verbose) 
            write("---> Checking columns with missing values...", 
                "")
        x <- t(na.omit(t(x)))
        if (verbose && length(attr(x, "na.action")) > 0) {
            write(paste("--->\t WARNING:", length(attr(x, "na.action")), 
                "columns found with missing values"), "")
        }
        if (detrend[[nvar]]) {
            if (verbose) 
                write("---> Removing linear trend...", "")
            x <- x - t(fitted(lm(t(x) ~ as.integer(colnames(x)))))
        }
        if (standardize[[nvar]]) {
            if (verbose) 
                write("---> Standardizing data...", "")
            x <- x/sqrt(v)
            v <- rep(1, n)
            x <- x * sqrt(m - 1)
        }
        else {
            v <- v/(m - 1)
        }
        if (!standardize[[nvar]]) {
            if (length(mask) > 0) {
                x <- x + xmean[-mask]
            }
            else {
                x <- x + xmean
            }
        }
        xxx <- cbind(xxx, weightMVC[[nvar]] * x)
        missVal[[nvar]] <- attr(x, "na.action")
    }
    x <- xxx
    rm(xxx, xx, mm0)
    n <- dim(x)[1]
    m <- dim(x)[2]
    if (is.null(n)) 
        stop("invalid data size")
    if (is.na(n)) 
        stop("size cannot be NA")
    if (n < 2) 
        stop("must have n <U+2265> 2 objects to cluster")
    if (nvars > 1) {
        if (verbose) 
            write("---> Updating variance for multivariate clustering...", 
                "")
        v <- rowSums(x^2, na.rm = TRUE)/(m - 1)
    }
    if (!is.null(nPC)) {
        if (verbose) 
            write("---> Reconstructing data from PCs...", "")
        if (nPC >= 1 && nPC <= min(n, m)) {
            xSVD <- La.svd(t(x), nPC, nPC)
            eigVal <- xSVD$d
            expVar <- eigVal^2/sum(eigVal^2) * 100
            accVar <- sapply(seq(1, length(expVar)), function(r) sum(expVar[1:r]))
            x1 <- xSVD$u %*% diag(xSVD$d[1:nPC], nPC, nPC) %*% 
                xSVD$vt
            x1 <- t(x1) - colMeans(x1)
            rm(xSVD)
        }
        else {
            stop(paste("invalid number of PCs,", 1, "<U+2264> nPC <U+2264>", 
                min(m, n)))
        }
    }
    if (verbose) 
        write("Agglomerative Hierarchical Clustering...", "")
    if (verbose) 
        write("---> Computing correlation/dissimilarity matrix...", 
            "")
    if (!is.null(nPC)) {
        v1 <- rowSums(x1^2, na.rm = TRUE)
        r1 <- fastCor(t(x1), nSplit = nSplit, upperTri = TRUE, 
            verbose = verbose)
        r1 <- r1[col(r1) < row(r1)]
        v1 <- v1/(m - 1)
    }
    else {
        r <- fastCor(t(x), nSplit = nSplit, upperTri = TRUE, 
            verbose = verbose)
        r <- r[col(r) < row(r)]
        x1 <- x
        v1 <- v
        r1 <- r
    }
    if (!rawStats) {
        x <- x1
        v <- v1
        r <- r1
    }
    d <- 1 - r1
    if (contigConst > 0 && pmatch(method, "regional", nomatch = 0) == 
        0 && !is.null(lon) && !is.null(lat)) {
        if (verbose) 
            write("---> Applying contiguity constraint...", "")
        if (length(mask) > 0) {
            dcontig <- dist(cbind(lon[-mask], lat[-mask]))
        }
        else {
            dcontig <- dist(cbind(lon, lat))
        }
        d <- d + contigConst * dcontig * max(d)/max(dcontig)
    }
    len <- as.integer(n * (n - 1)/2)
    if (length(d) != len) 
        (if (length(d) < len) 
            stop
        else warning)("data of improper length")
    rm(x1, r1)
    METHODS <- c("regional", "ward", "single", "complete", "average", 
        "mcquitty", "median", "centroid")
    method <- pmatch(method, METHODS) - 1
    if (is.na(method)) 
        stop("invalid clustering method")
    if (method == -1) 
        stop("ambiguous clustering method")
    if (is.null(members)) 
        members <- rep(1, n)
    else if (length(members) != n) 
        stop("invalid length of members")
    if (verbose) 
        write("---> Starting clustering process...", "")
    storage.mode(d) <- "double"
    hcl <- .Fortran("HiClimR", n = n, len = len, method = as.integer(method), 
        ia = integer(n), ib = integer(n), crit = double(n), members = as.double(members), 
        var = v, diss = d, PACKAGE = "HiClimR")
    hcass <- .Fortran("hcass2", n = n, ia = hcl$ia, ib = hcl$ib, 
        order = integer(n), iia = integer(n), iib = integer(n), 
        PACKAGE = "HiClimR")
    if (verbose) 
        write("---> Constructing dendrogram tree...", "")
    tree <- list(merge = cbind(hcass$iia[1L:(n - 1)], hcass$iib[1L:(n - 
        1)]), height = hcl$crit[1L:(n - 1)], order = hcass$order, 
        labels = rownames(x), method = METHODS[method + 1], call = match.call(), 
        dist.method = "correlation")
    class(tree) <- "hclust"
    tree$skip <- c(lonStep, latStep)
    names(tree$skip) <- c("lonStep", "latStep")
    if (!is.null(nPC)) {
        tree$PCA = cbind(eigVal = eigVal, expVar = expVar, accVar = accVar)
    }
    if (!is.null(lon) && !is.null(lat)) {
        tree$coords <- cbind(lon, lat)
        colnames(tree$coords) <- c("Lon", "Lat")
    }
    if (rawStats) {
        tree$data <- x
    }
    else {
        tree$data <- x1
    }
    tree$nvars <- nvars
    tree$ncols <- mm
    if (length(mask) > 0) {
        tree$mask <- mask
    }
    tree$missVal <- missVal
    if (hybrid) {
        if (verbose) 
            write("Hybrid Hierarchical Clustering...", "")
        if (verbose && tree$method == "regional") {
            write("---> WARNING: hybrid option is redundant when using regional linkage method!", 
                "")
        }
        else {
            if (is.null(kH)) {
                kH <- length(tree$height) - min(which(diff(tree$height) > 
                  mean(diff(tree$height)))) + 1
            }
            kH <- as.integer(kH)
            if (kH < 2) 
                stop("must have kH <U+2265> 2 objects to cluster")
            lenH <- as.integer(kH * (kH - 1)/2)
            methodH <- pmatch("regional", METHODS) - 1
            if (verbose) 
                write("---> Updating correlation/dissimilarity matrix...", 
                  "")
            cutTreeH <- cutree(tree, k = kH)
            RMH <- t(apply(tree$data, 2, function(r) tapply(r, 
                cutTreeH, mean)))
            vH <- apply(RMH, 2, var)
            rH <- fastCor(RMH, nSplit = nSplit, upperTri = TRUE, 
                verbose = verbose)
            rH <- rH[col(rH) < row(rH)]
            dH <- 1 - rH
            if (verbose) 
                write("---> Reonstructing the upper part of the tree...", 
                  "")
            storage.mode(d) <- "double"
            hclH <- .Fortran("HiClimR", n = kH, len = lenH, method = as.integer(methodH), 
                ia = integer(kH), ib = integer(kH), crit = double(kH), 
                members = as.double(table(cutTreeH)), var = vH, 
                diss = dH, PACKAGE = "HiClimR")
            hcassH <- .Fortran("hcass2", n = kH, ia = hclH$ia, 
                ib = hclH$ib, order = integer(kH), iia = integer(kH), 
                iib = integer(kH), PACKAGE = "HiClimR")
            treeH <- list(merge = cbind(hcassH$iia[1L:(kH - 1)], 
                hcassH$iib[1L:(kH - 1)]), height = hclH$crit[1L:(kH - 
                1)], order = hcassH$order, labels = names(table(cutree(tree, 
                kH))), method = METHODS[methodH + 1], call = match.call(), 
                dist.method = "correlation")
            class(treeH) <- "hclust"
            if (verbose) 
                write("---> Merging upper and lower parts of the tree...", 
                  "")
            tree$treeH <- treeH
        }
    }
    if (plot && dendrogram) {
        dev.new()
        if (hybrid && tree$method != "regional") {
            opar <- par(mfrow = c(1, 2))
            plot(tree, hang = hang, labels = labels, main = paste(METHODS[method + 
                1], "Method | Original Tree"))
            plot(treeH, hang = hang, labels = FALSE, main = paste("Regional Linkage |", 
                kH, "clusters"), axes = FALSE, ylab = "Maximum Inter-Regional Correlation")
            axis(2, at = pretty(treeH$height), labels = 1 - pretty(treeH$height))
            par(opar)
        }
        else {
            if (tree$method == "regional") {
                plot(tree, hang = hang, labels = labels, axes = FALSE, 
                  ylab = "Maximum Inter-Regional Correlation")
                axis(2, at = pretty(tree$height), labels = 1 - 
                  pretty(tree$height))
            }
            else {
                plot(tree, hang = hang, labels = labels)
            }
        }
    }
    if (validClimR) {
        if (verbose) 
            write("Calling cluster validation...", "")
        z <- validClimR(y = tree, k = k, minSize = minSize, alpha = alpha, 
            verbose = verbose, plot = plot, colPalette = colPalette, 
            pch = pch, cex = cex)
        tree <- c(tree, z)
    }
    class(tree) <- c("hclust", "HiClimR")
    if (verbose) 
        write("\nPROCESSING COMPLETED", "")
    write("\nRunning Time:", "")
    print(proc.time() - start.time.proc)
    print(Sys.time() - start.time.sys)
    gc()
    tree
}
<bytecode: 0x2680768>
<environment: namespace:HiClimR>
 --- function search by body ---
Function HiClimR in namespace HiClimR has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1