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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: formatsitepair
> ### Title: Converts Common Biological (Response) and Environmental
> ###   (Predictor) Data Formats to a GDM Site-Pair Table
> ### Aliases: formatsitepair
> ### Keywords: gdm
> 
> ### ** Examples
> 
> 
> ##table data, species and environmental
> load(system.file("./data/gdm.RData", package="gdm"))
> sppData <- gdmExpData[, c(1,2,13,14)]
> envTab <- gdmExpData[, c(2:ncol(gdmExpData))]
> 
> ##environmental raster data
> ##commented out to reduce example run time
> #rastFile <- system.file("./extdata/stackedVars.grd", package="gdm")
> #envRast <- stack(rastFile)
> 
> #########table type 1
> ##site-species table without coordinates
> testData1a <- reshape2::dcast(sppData, site~species)
Using Long as value column: use value.var to override.
Aggregation function missing: defaulting to length
> ##site-species table with coordinates
> coords <- unique(sppData[, 2:ncol(sppData)])
> testData1b <- merge(testData1a, coords, by="site")
> ##site-species, table-table
> exFormat1a <- formatsitepair(testData1a, 1, siteColumn="site", XColumn="Long", YColumn="Lat",
+ 	predData=envTab)
> 
> ##site-species, table-raster
> ##not run
> #exFormat1b <- formatsitepair(testData1b, 1, siteColumn="site", XColumn="Long", YColumn="Lat",
> #	predData=envRast)
> 
> #########table type 2
> ##site xy spp list, table-table
> exFormat2a <- formatsitepair(sppData, 2, XColumn="Long", YColumn="Lat", sppColumn="species",
+ 	siteColumn="site", predData=envTab)
Warning in formatsitepair(sppData, 2, XColumn = "Long", YColumn = "Lat",  :
  No abundance column specified, assuming species data are presence
Aggregation function missing: defaulting to length
> ##site xy spp list, table-raster
> ##commented out to reduce example run time
> #exFormat2b <- formatsitepair(sppData, 2, XColumn="Long", YColumn="Lat", sppColumn="species",
> #	siteColumn="site", predData=envRast)
> 
> #########table type 3
> ##dissim matrix model
> site <- unique(sppData$site)
> gdmDissim <- cbind(site, gdmDissim)
> exFormat3 <- formatsitepair(gdmDissim, 3, XColumn="Long", YColumn="Lat", predData=envTab,
+ 	siteColumn="site")
> 
> #########table type 4
> ##adds a predictor matrix to an existing site-pair table, in this case, predData needs to be
> ##filled, but is not actually used
> exFormat4 <- formatsitepair(exFormat2a, 4, predData=envTab, siteColumn="site",
+ 	distPreds=list(as.matrix(gdmDissim)))
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
gdm
 --- call from context --- 
formatsitepair(exFormat2a, 4, predData = envTab, siteColumn = "site", 
    distPreds = list(as.matrix(gdmDissim)))
 --- call from argument --- 
if (class(mat) != "matrix" & class(mat) != "data.frame") {
    warning("One or more of the provided distance predictor matrices are not of class 'matrix'.")
}
 --- R stacktrace ---
where 1: formatsitepair(exFormat2a, 4, predData = envTab, siteColumn = "site", 
    distPreds = list(as.matrix(gdmDissim)))

 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context --- 
function (bioData, bioFormat, dist = "bray", abundance = FALSE, 
    siteColumn = NULL, XColumn, YColumn, sppColumn = NULL, abundColumn = NULL, 
    sppFilter = 0, predData, distPreds = NULL, weightType = "equal", 
    custWeights = NULL, sampleSites = 1) 
{
    if (!(class(bioData)[1] == "data.frame" | class(bioData)[1] == 
        "matrix" | class(bioData)[1] == "gdmData")) {
        "bioData should be a data frame or matrix in one of the acceptable formats"
    }
    if (class(bioData)[1] == "data.frame" | class(bioData)[1] == 
        "matrix") {
        bioData <- as.data.frame(bioData, stringsAsFactors = F)
    }
    if (!(class(predData) == "data.frame" | class(predData) == 
        "matrix" | class(predData) == "RasterStack" | class(predData) == 
        "RasterLayer" | class(predData) == "RasterBrick")) {
        "predData should be a data frame, matrix, or raster in one of the acceptable formats"
    }
    if (class(predData)[1] == "data.frame" | class(predData)[1] == 
        "matrix") {
        predData <- as.data.frame(predData, stringsAsFactors = F)
    }
    if (bioFormat %in% c(1:4)) {
    }
    else {
        stop("Acceptable values for the bioFormat argument are: 1, 2, 3, or 4")
    }
    if (!(abundance == TRUE | abundance == FALSE)) {
        stop("abundance argument must be either TRUE or FALSE")
    }
    if (is.null(sampleSites) == TRUE) {
        stop("sampleSites argument must be a number between 0-1")
    }
    if (is.numeric(sampleSites) == FALSE | sampleSites < 0 | 
        sampleSites > 1) {
        stop("sampleSites argument must be a number between 0-1")
    }
    if ((is.numeric(sppFilter) == FALSE & is.null(sppFilter) == 
        FALSE) | sppFilter < 0) {
        stop("sppFilter argument must be a positive integer")
    }
    if (weightType %in% c("equal", "richness", "custom")) {
    }
    else {
        stop("Acceptable values for the weightType argument are: equal, richness, or custom")
    }
    if (weightType == "custom" & is.null(custWeights) == T) {
        stop("custom weightType provided with no custWeights")
    }
    if (bioFormat == 2 & is.null(sppColumn) == TRUE) {
        stop("Need to define sppColumn argument when bioFormat==2")
    }
    if (bioFormat == 2 & is.null(siteColumn) == TRUE) {
        if (!(class(predData) == "RasterStack" | class(predData) == 
            "RasterLayer" | class(predData) == "RasterBrick")) {
            stop("A siteColumn needs to be provided in either the bioData or predData inputs")
        }
    }
    if (is.null(siteColumn) == FALSE) {
        if (class(siteColumn) != "character") {
            stop("siteColumn argument needs to be as type character")
        }
        else if (!(siteColumn %in% colnames(bioData)) & (bioFormat == 
            1 | bioFormat == 2)) {
            stop("Cannot find a match for siteColumn in the columns of bioData.")
        }
    }
    if (bioFormat != 4) {
        if (class(XColumn) != "character") {
            stop("XColumn argument needs to be as type character")
        }
        else if (class(YColumn) != "character") {
            stop("YColumn argument needs to be as type character")
        }
        else if (!(XColumn %in% colnames(bioData) | XColumn %in% 
            colnames(predData))) {
            stop("XColumn not found in either the bioData or predData arguments")
        }
        else if (!(YColumn %in% colnames(bioData) | YColumn %in% 
            colnames(predData))) {
            stop("YColumn not found in either the bioData or predData arguments")
        }
    }
    if (bioFormat == 3) {
        if (weightType == "richness") {
            stop("Cannot weight by site richness when supplying the biological data as a distance matrix.")
        }
        else if (nrow(bioData) != (ncol(bioData) - 1)) {
            stop("Biological dissimilarity has differing number of rows to number of columns. Did you forget to add a column for site ID's?")
        }
    }
    for (mat in distPreds) {
        if (class(mat) != "matrix" & class(mat) != "data.frame") {
            warning("One or more of the provided distance predictor matrices are not of class 'matrix'.")
        }
    }
    if (is.null(custWeights) == FALSE & (class(custWeights) != 
        "data.frame" & class(custWeights) != "matrix")) {
        stop("argument custWeights needs to be a data frame or matrix data type")
    }
    toRemove <- NULL
    removeRand <- NULL
    distData <- NULL
    if (bioFormat == 1 | bioFormat == 2) {
        if (bioFormat == 2) {
            if ((sppColumn %in% colnames(bioData))) {
            }
            else {
                stop("Cannot find sppColumn in bioData - check name?")
            }
            if (is.null(siteColumn)) {
                colnames(bioData)[which(colnames(bioData) == 
                  XColumn)] <- "myXness"
                colnames(bioData)[which(colnames(bioData) == 
                  YColumn)] <- "myYness"
                bioData <- transform(bioData, siteUltimateCoolness = as.numeric(interaction(bioData$myXness, 
                  bioData$myYness, drop = TRUE)))
                siteColumn <- "siteUltimateCoolness"
                colnames(bioData)[which(colnames(bioData) == 
                  "myXness")] <- XColumn
                colnames(bioData)[which(colnames(bioData) == 
                  "myYness")] <- YColumn
            }
            if (is.null(abundColumn)) {
                warning("No abundance column specified, assuming species data are presence")
                bioData["reallysupercoolawesomedata"] <- 1
                abundColumn <- "reallysupercoolawesomedata"
            }
            preCastBio <- bioData
            colnames(preCastBio)[which(colnames(preCastBio) == 
                siteColumn)] <- "siteUltimateCoolness"
            colnames(preCastBio)[which(colnames(preCastBio) == 
                sppColumn)] <- "spcodeUltimateCoolness"
            castData <- reshape2::dcast(preCastBio, fill = 0, 
                siteUltimateCoolness ~ spcodeUltimateCoolness, 
                value.var = abundColumn)
            uniqueCoords <- unique(preCastBio[which(colnames(preCastBio) %in% 
                c("siteUltimateCoolness", XColumn, YColumn))])
            bioData <- merge(castData, uniqueCoords, by = "siteUltimateCoolness")
            colnames(bioData)[which(colnames(bioData) == "siteUltimateCoolness")] <- siteColumn
        }
        if ((XColumn %in% colnames(bioData)) == FALSE | (YColumn %in% 
            colnames(bioData) == FALSE)) {
            xCol <- which(colnames(predData) == XColumn)
            yCol <- which(colnames(predData) == YColumn)
            locs <- predData[c(xCol, yCol)]
        }
        else {
            xCol <- which(colnames(bioData) == XColumn)
            yCol <- which(colnames(bioData) == YColumn)
            locs <- bioData[c(xCol, yCol)]
        }
        if (class(predData) == "RasterStack" | class(predData) == 
            "RasterLayer" | class(predData) == "RasterBrick") {
            warning("With raster prediction data, defaulting sites to cells.")
            cellID <- as.data.frame(cellFromXY(predData, locs))
            colnames(cellID)[which(colnames(cellID) == "cellFromXY(predData, locs)")] <- "cellName"
            if (nrow(cellID) == sum(is.na(cellID$cellName))) {
                stop("None of the given points intersect with the given raster data. Double check that your geography is correct and that the given XColumn and YColumn values are correct.")
            }
            cellLocs <- as.data.frame(xyFromCell(predData, cellID$cellName))
            rastBioData <- cbind(cellID, cellLocs, bioData[-c(which(colnames(bioData) %in% 
                c(XColumn, YColumn)))])
            if (weightType == "custom" & !is.null(custWeights)) {
                nameTab <- unique(rastBioData[c("cellName", siteColumn)])
                tempWeightTab <- merge(x = nameTab, y = custWeights, 
                  by = siteColumn)
                siteNum <- which(colnames(tempWeightTab) == "cellName")
                custWeights <- tempWeightTab[-siteNum]
                colnames(custWeights)[1] <- siteColumn
            }
            siteNum <- which(colnames(rastBioData) == siteColumn)
            rastBioData <- rastBioData[-siteNum]
            cellNum <- which(colnames(rastBioData) == "cellName")
            bioData <- aggregate(rastBioData, rastBioData[cellNum], 
                FUN = mean)
            bioData <- bioData[-cellNum]
            rastEx <- as.data.frame(extract(predData, bioData$cellName))
            colnames(bioData)[which(colnames(bioData) == "cellName")] <- siteColumn
            colnames(bioData)[which(colnames(bioData) == "x")] <- XColumn
            colnames(bioData)[which(colnames(bioData) == "y")] <- YColumn
            xCol <- which(colnames(bioData) == XColumn)
            yCol <- which(colnames(bioData) == YColumn)
            locs <- bioData[c(xCol, yCol)]
            siteCol <- which(colnames(bioData) == siteColumn)
            predData <- cbind(bioData[siteCol], locs, rastEx)
        }
        siteCol <- which(colnames(bioData) == siteColumn)
        xCol <- which(colnames(bioData) == XColumn)
        yCol <- which(colnames(bioData) == YColumn)
        sppDat <- bioData[-c(siteCol, xCol, yCol)]
        sppDat[sppDat >= 1] <- 1
        sppDat[sppDat == 0] <- 0
        sppDat[is.na(sppDat)] <- 0
        sppTotals <- cbind.data.frame(bioData[, siteCol], apply(sppDat, 
            1, function(m) {
                sum(as.numeric(m))
            }))
        colnames(sppTotals) <- c(siteColumn, "totals")
        filterBioDat <- subset(sppTotals, sppTotals[colnames(sppTotals)[2]] >= 
            sppFilter)
        toRemove <- bioData[, siteCol][which(!(bioData[, siteCol] %in% 
            filterBioDat[, siteColumn]))]
        spSiteCol <- filterBioDat[1]
        bioData <- unique(merge(spSiteCol, bioData, by = siteColumn))
        if (is.null(sampleSites) == FALSE) {
        }
        else {
            fullSites <- bioData[, siteCol]
            randRows <- sample(1:nrow(bioData), round(nrow(bioData) * 
                sampleSites, 0))
            bioData <- bioData[c(randRows), ]
            removeRand <- fullSites[which(!(fullSites %in% bioData[, 
                siteCol]))]
        }
        colnames(bioData)[colnames(bioData) == siteColumn] <- "gettingCoolSiteColumn"
        colnames(predData)[colnames(predData) == siteColumn] <- "gettingCoolSiteColumn"
        predData <- unique(predData)
        predData <- predData[which(predData$gettingCoolSiteColumn %in% 
            as.character(bioData$gettingCoolSiteColumn)), ]
        if (weightType == "custom" & !is.null(custWeights)) {
            colnames(custWeights)[colnames(custWeights) == siteColumn] <- "gettingCoolSiteColumn"
            custWeights <- custWeights[which(predData$gettingCoolSiteColumn %in% 
                custWeights[, "gettingCoolSiteColumn"]), ]
            custWeights <- custWeights[order(custWeights[, "gettingCoolSiteColumn"]), 
                ]
            colnames(custWeights)[colnames(custWeights) == "gettingCoolSiteColumn"] <- siteColumn
        }
        colnames(bioData)[colnames(bioData) == "gettingCoolSiteColumn"] <- siteColumn
        colnames(predData)[colnames(predData) == "gettingCoolSiteColumn"] <- siteColumn
        predSite <- which(names(predData) == siteColumn)
        bioSite <- which(names(bioData) == siteColumn)
        predData <- predData[order(predData[, predSite]), ]
        bioData <- bioData[order(bioData[, bioSite]), ]
        bx <- which(names(bioData) == XColumn)
        by <- which(names(bioData) == YColumn)
        sppData <- bioData[-c(bioSite, bx, by)]
        if (abundance == F) {
            sppData[sppData >= 1] <- 1
            sppData[sppData == 0] <- 0
            sppData[is.na(sppData)] <- 0
            distData <- vegan::vegdist(sppData, dist, binary = T)
        }
        else {
            sppData[is.na(sppData)] <- 0
            distData <- vegan::vegdist(sppData, dist, binary = F)
        }
    }
    else if (bioFormat == 3) {
        holdSite <- bioData[, which(siteColumn %in% colnames(bioData))]
        bioData <- bioData[, -which(siteColumn %in% colnames(bioData))]
        orderedData <- as.matrix(as.dist(bioData[order(holdSite), 
            order(holdSite)]))
        distData <- lower.tri(as.matrix(orderedData), diag = FALSE)
        distData <- as.vector(orderedData[distData])
        predData <- unique(predData)
        predData <- predData[order(predData[siteColumn]), ]
    }
    else if (bioFormat == 4) {
        outTable <- bioData
    }
    else {
        stop(paste("bioFormat argument of '", as.character(bioFormat), 
            "' is not an accepted input value", sep = ""))
    }
    if (bioFormat != 4) {
        outTable <- as.data.frame(createsitepair(dist = distData, 
            spdata = bioData, envInfo = predData, dXCol = XColumn, 
            dYCol = YColumn, siteCol = siteColumn, weightsType = weightType, 
            custWeights = custWeights))
    }
    else {
        outTable <- bioData
    }
    if (length(distPreds) > 0) {
        baseMat <- distPreds[[1]]
        lapply(distPreds, function(mat, mat1) {
            if ((dim(mat1)[1] != dim(mat)[1]) & (dim(mat1)[2] != 
                dim(mat)[2])) {
                stop("The dimensions of your predictor matrices are not the same.")
            }
        }, mat1 = baseMat)
        holdSiteCols <- lapply(distPreds, function(dP) {
            dP[, which(siteColumn %in% colnames(dP))]
        })
        distPreds <- lapply(distPreds, function(dP) {
            dP[, -which(siteColumn %in% colnames(dP))]
        })
        distPreds <- mapply(function(dP, hSC) {
            as.matrix(as.dist(dP[order(hSC), order(hSC)]))
        }, dP = distPreds, hSC = holdSiteCols, SIMPLIFY = FALSE)
        orderSiteCols <- lapply(holdSiteCols, function(hSC) {
            hSC[order(hSC)]
        })
        rmSites <- c(toRemove, removeRand)
        if (length(rmSites) > 0) {
            rmIndex <- lapply(orderSiteCols, function(hSC, tR) {
                which((hSC %in% tR))
            }, tR = rmSites)
            distPreds <- mapply(function(mat, tR) {
                mat[-c(tR), -c(tR)]
            }, mat = distPreds, tR = rmIndex, SIMPLIFY = FALSE)
        }
        baseMat <- distPreds[[1]]
        baseMatDat <- lower.tri(as.matrix(baseMat), diag = FALSE)
        baseMatDat <- as.vector(baseMat[baseMatDat])
        if (nrow(outTable) != length(baseMatDat)) {
            stop("The dimensions of the distance predictor matrices do not match the biological data.")
        }
        for (num in 1:length(distPreds)) {
            matrixDat <- lower.tri(as.matrix(distPreds[[num]], 
                diag = FALSE))
            sweetFreakenPredMatrix <- as.vector(distPreds[[num]][matrixDat])
            if (ncol(outTable) > 6) {
                baseSitePair <- outTable[, 1:6]
                otherSitePair <- outTable[, 7:ncol(outTable)]
                otherNames <- colnames(otherSitePair)
                s1SitePair <- as.data.frame(otherSitePair[, 1:(ncol(otherSitePair)/2)])
                colnames(s1SitePair) <- otherNames[1:(ncol(otherSitePair)/2)]
                s2SitePair <- as.data.frame(otherSitePair[, (ncol(otherSitePair)/2 + 
                  1):ncol(otherSitePair)])
                colnames(s2SitePair) <- otherNames[(ncol(otherSitePair)/2 + 
                  1):ncol(otherSitePair)]
                s1Zeros <- as.data.frame(rep(0, length(sweetFreakenPredMatrix)))
                colnames(s1Zeros) <- paste("s1.matrix_", num, 
                  sep = "")
                s2Mat <- as.data.frame(sweetFreakenPredMatrix)
                colnames(s2Mat) <- paste("s2.matrix_", num, sep = "")
                outTable <- cbind(baseSitePair, s1SitePair, s1Zeros, 
                  s2SitePair, s2Mat)
            }
            else {
                s1Zeros <- as.data.frame(rep(0, length(sweetFreakenPredMatrix)))
                colnames(s1Zeros) <- paste("s1.matrix_", num, 
                  sep = "")
                s2Mat <- as.data.frame(sweetFreakenPredMatrix)
                colnames(s2Mat) <- paste("s2.matrix_", num, sep = "")
                outTable <- cbind(outTable, s1Zeros, s2Mat)
            }
        }
    }
    class(outTable) <- c("gdmData", "data.frame")
    return(outTable)
}
<bytecode: 0x1397d7f8>
<environment: namespace:gdm>
 --- function search by body ---
Function formatsitepair in namespace gdm has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(mat) != "matrix" & class(mat) != "data.frame") { : 
  the condition has length > 1
Calls: formatsitepair
Execution halted