Running examples in ‘virtualspecies-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: sampleOccurrences
> ### Title: Sample occurrences in a virtual species distribution
> ### Aliases: sampleOccurrences
> 
> ### ** Examples
> 
> # Create an example stack with six environmental variables
> a <- matrix(rep(dnorm(1:100, 50, sd = 25)), 
+             nrow = 100, ncol = 100, byrow = TRUE)
> env <- stack(raster(a * dnorm(1:100, 50, sd = 25)),
+              raster(a * 1:100),
+              raster(a * logisticFun(1:100, alpha = 10, beta = 70)),
+              raster(t(a)),
+              raster(exp(a)),
+              raster(log(a)))
> names(env) <- paste("Var", 1:6, sep = "")   
> 
> # More than 6 variables: by default a PCA approach will be used
> sp <- generateRandomSp(env, niche.breadth = "wide")
 - Perfoming the pca

 - Defining the response of the species along PCA axes

 - Calculating suitability values

Warning in if (class(test) == "try-error") { :
  the condition has length > 1 and only the first element will be used
   The final environmental suitability was rescaled between 0 and 1.
                  To disable, set argument rescale = FALSE
 - Converting into Presence - Absence

   --- Generating a random value of beta for the logistic conversion


   --- Determing species.prevalence automatically according to alpha and beta


   Logistic conversion finished:
              
- beta = 0.128128128128128
- alpha = -0.1
- species prevalence =0.924


> 
> # Sampling of 25 presences
> sampleOccurrences(sp, n = 25)
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
virtualspecies
 --- call from context --- 
.randomPoints(sample.raster, n = number.errors, prob = TRUE, 
    tryf = 1, replaceCells = replacement)
 --- call from argument --- 
if (class(cells) == "try-error") {
    stop("the raster is too large to be used with 'prob=TRUE'")
}
 --- R stacktrace ---
where 1: .randomPoints(sample.raster, n = number.errors, prob = TRUE, 
    tryf = 1, replaceCells = replacement)
where 2: sampleOccurrences(sp, n = 25)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (mask, n, p, ext = NULL, extf = 1.1, excludep = TRUE, 
    prob = FALSE, cellnumbers = FALSE, tryf = 3, warn = 2, lonlatCorrection = TRUE, 
    replaceCells = FALSE) 
{
    if (nlayers(mask) > 1) {
        mask <- raster(mask, 1)
    }
    tryf <- max(round(tryf[1]), 1)
    if (missing(p)) {
        excludep <- FALSE
    }
    else {
        if (inherits(p, "SpatialPoints")) {
            p <- sp::coordinates(p)
        }
    }
    if (class(ext) == "character") {
        if (!ext %in% c("points")) {
            stop("if ext is a character variable it should be 'points'")
        }
        else if (missing(p)) {
            warning("if p is missing, 'ext=points' is meaningless")
            ext <- extent(mask)
        }
        else {
            ext <- extent(min(p[, 1]), max(p[, 1]), min(p[, 2]), 
                max(p[, 2]))
        }
    }
    if (!is.null(ext)) {
        ext <- extent(ext)
        ext <- ext * extf
        ext <- intersect(ext, extent(mask))
        mask2 <- crop(raster(mask), ext)
    }
    else {
        mask2 <- raster(mask)
    }
    nn <- n * tryf
    nn <- max(nn, 10)
    if (prob) {
        stopifnot(hasValues(mask))
        cells <- crop(mask, mask2)
        cells <- try(stats::na.omit(cbind(1:ncell(cells), getValues(cells))))
        if (class(cells) == "try-error") {
            stop("the raster is too large to be used with 'prob=TRUE'")
        }
        prob <- cells[, 2]
        cells <- cells[, 1]
        if (couldBeLonLat(mask)) {
            rows <- rowFromCell(mask2, cells)
            y <- yFromRow(mask2, rows)
            dx <- pointDistance(cbind(0, y), cbind(xres(mask2), 
                y), longlat = TRUE)
            prob <- prob * dx
        }
        cells <- sample(cells, nn, prob = prob, replace = replaceCells)
        xy <- xyFromCell(mask2, cells)
        cells <- cellFromXY(mask, xy)
    }
    else if (canProcessInMemory(mask2)) {
        cells <- crop(mask, mask2)
        if (hasValues(cells)) {
            cells <- which(!is.na(getValues(cells)))
        }
        else {
            cells <- 1:ncell(cells)
        }
        nn <- min(length(cells), nn)
        if (lonlatCorrection & couldBeLonLat(mask)) {
            rows <- rowFromCell(mask2, cells)
            y <- yFromRow(mask2, rows)
            dx <- pointDistance(cbind(0, y), cbind(xres(mask2), 
                y), longlat = TRUE)
            cells <- sample(cells, nn, prob = dx, replace = replaceCells)
        }
        else {
            cells <- sample(cells, nn, replace = replaceCells)
        }
        xy <- xyFromCell(mask2, cells)
        cells <- cellFromXY(mask, xy)
    }
    else {
        nn <- min(ncell(mask2), nn)
        if (couldBeLonLat(mask2)) {
            cells <- .randomCellsLonLat(mask2, nn)
        }
        else {
            if (nn >= ncell(mask2)) {
                cells <- 1:ncell(mask2)
            }
            else {
                cells <- sampleInt(ncell(mask2), nn, replace = replaceCells)
            }
        }
        xy <- xyFromCell(mask2, cells)
        cells <- cellFromXY(mask, xy)
        if (hasValues(mask)) {
            vals <- cbind(cells, extract(mask, cells))
            cells <- stats::na.omit(vals)[, 1]
        }
    }
    if (excludep) {
        pcells <- cellFromXY(mask, p)
        cells <- cells[!(cells %in% pcells)]
    }
    if (length(cells) > n) {
        cells <- sample(cells, n)
    }
    else if (length(cells) < n) {
        frac <- length(cells)/n
        if (frac < 0.1) {
            stop("generated random points = ", frac, " times requested number; Use a higher value for tryf")
        }
        if (frac < 0.5 & warn == 1) {
            warning("generated random points = ", frac, " times requested number; Use a higher value for tryf")
        }
        else if (warn > 1) {
            warning("generated random points = ", frac, " times requested number")
        }
    }
    if (cellnumbers) {
        return(cells)
    }
    else {
        return(xyFromCell(mask, cells))
    }
}
<bytecode: 0x56322c356268>
<environment: namespace:virtualspecies>
 --- function search by body ---
Function .randomPoints in namespace virtualspecies has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1