Running ‘tests.R’ [39s/65s]
Running the tests in ‘tests/tests.R’ failed.
Complete output:
  > library(virtualspecies)
  Loading required package: terra
  terra 1.7.78
  > a <- matrix(rep(dnorm(1:100, 50, sd = 25)),
  +             nrow = 100, ncol = 100, byrow = TRUE)
  > env <- c(rast(a * dnorm(1:100, 50, sd = 25)),
  +          rast(a * 1:100))
  > names(env) <- c("variable1", "variable2")
  > plot(env) # Illustration of the variables
  > 
  > # Easy creation of the parameter list:
  > # see in real time the shape of the response functions
  > parameters <- formatFunctions(variable1 = c(fun = 'dnorm', mean = 1e-04,
  +                                              sd = 1e-04),
  +                               variable2 = c(fun = 'linearFun', a = 1, b = 0))
  > 
  > plotResponse(x = env, parameters = parameters, 
  +              approach = "response")
  No default value was defined for rescale.each.response, setting rescale.each.response = TRUE
  No default value was defined for rescale.each.response, setting rescale.each.response = TRUE
  > 
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
  > 
  > # If you provide env, then you can see the shape of response functions:
  > parameters <- formatFunctions(x = env,
  +                               variable1 = c(fun = 'dnorm', mean = 1e-04,
  +                                              sd = 1e-04),
  +                               variable2 = c(fun = 'linearFun', a = 1, b = 0))
  No default value was defined for rescale.each.response, setting rescale.each.response = TRUE
  No default value was defined for rescale.each.response, setting rescale.each.response = TRUE
  > 
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = NULL,
  +                          species.type = "additive")
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = NULL,
  +                          species.type = "multiplicative")
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = NULL,
  +                          species.type = "multiplicative",
  +                          rescale = FALSE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = NULL,
  +                          species.type = "multiplicative",
  +                          rescale = FALSE,
  +                          rescale.each.response = FALSE)
  Generating virtual species environmental suitability...
  
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = "variable1 + variable2",
  +                          species.type = "multiplicative",
  +                          rescale = FALSE,
  +                          rescale.each.response = TRUE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
  [1] "variable1 + variable2"
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = "sqrt(variable1) + variable2 + 2 * variable2^2 + variable2^3",
  +                          species.type = "multiplicative",
  +                          rescale = FALSE,
  +                          rescale.each.response = TRUE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
  [1] "sqrt(variable1) + variable2 + 2 * variable2^2 + variable2^3"
  > sp1 <- generateSpFromFun(env, parameters, plot = TRUE,
  +                          formula = "sqrt(variable1) + variable2 + 2 * variable2^2 + variable2^3",
  +                          species.type = "multiplicative",
  +                          rescale = TRUE,
  +                          rescale.each.response = TRUE)
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
  [1] "sqrt(variable1) + variable2 + 2 * variable2^2 + variable2^3"
  > 
  > 
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold")
     --- Generating a random value of beta for the threshold conversion
  
  
     Threshold conversion finished:
                
  - cutoff = 0.346346346346346
  - species prevalence =0.1706
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    beta = 0.5)
     Threshold conversion finished:
                
  - cutoff = 0.5
  - species prevalence =0.1023
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    beta = 0)
     Threshold conversion finished:
                
  - cutoff = 0
  - species prevalence =0.9999
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    beta = 1)
     Threshold conversion finished:
                
  - cutoff = 1
  - species prevalence =0
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    beta = "random")
     --- Generating a random value of beta for the threshold conversion
  
  
     Threshold conversion finished:
                
  - cutoff = 0.932932932932933
  - species prevalence =0.0043
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    species.prevalence = .2)
     Threshold conversion finished:
                
  - cutoff = 0.298037629032326
  - species prevalence =0.2
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    species.prevalence = .02)
     Threshold conversion finished:
                
  - cutoff = 0.8172017320348
  - species prevalence =0.0199
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    species.prevalence = .9)
     Threshold conversion finished:
                
  - cutoff = 0.0470198966430044
  - species prevalence =0.9
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "threshold",
  +                    species.prevalence = .99)
     Threshold conversion finished:
                
  - cutoff = 0.00959072698507723
  - species prevalence =0.9899
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = "random",
  +                    a = NULL,
  +                    b = NULL,
  +                    species.prevalence = .99)
     --- Determing beta automatically according to alpha and species.prevalence
  
  
     Logistic conversion finished:
                
  - beta = -0.1328125
  - alpha = -0.05
  - species prevalence =0.9894
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = "random",
  +                    a = NULL,
  +                    b = NULL,
  +                    species.prevalence = .5)
     --- Determing beta automatically according to alpha and species.prevalence
  
  
     Logistic conversion finished:
                
  - beta = 0.1492919921875
  - alpha = -0.05
  - species prevalence =0.4946
  
  
  > sp2 <- convertToPA(sp1,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = .5,
  +                    a = NULL,
  +                    b = NULL)
     --- Determing species.prevalence automatically according to alpha and beta
  
  
     Logistic conversion finished:
                
  - beta = 0.5
  - alpha = -0.05
  - species prevalence =0.1057
  
  
  > 
  > 
  > sp3 <- generateRandomSp(env)
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.613613613613614
  - alpha = -0.1
  - species prevalence =0.108
  
  
  > 
  > a <- matrix(rep(dnorm(1:100, 50, sd = 25)),
  +             nrow = 100, ncol = 100, byrow = TRUE)
  > 
  > env1 <- c(rast(a * dnorm(1:100, 50, sd = 25)),
  +           rast(a * 1:100),
  +           rast(a),
  +           rast(t(a)))
  > names(env1) <- c("var1", "var2", "var3", "var4")
  > b <- matrix(rep(dnorm(1:100, 25, sd = 50)),
  +             nrow = 100, ncol = 100, byrow = TRUE)
  > 
  > env2 <- c(rast(b * dnorm(1:100, 50, sd = 25)),
  +           rast(b * 1:100),
  +           rast(b),
  +           rast(t(b)))
  > 
  > names(env2) <- c("var1", "var2", "var3", "var4")
  > 
  > # Generating a species with the BCA
  > sp4 <- generateSpFromBCA(raster.stack.current = env1, raster.stack.future = env2)
  Reading raster values. If it fails for very large rasters, use arguments 'sample.points = TRUE' and define a number of points to sample with 'nb.point'.
   - Perfoming the between component analysis
  
   - Defining the response of the species along the axis
  
   - Calculating current suitability values
  
   - Calculating future suitability values
  
     The final environmental suitability was rescaled between 0 and1. To disable, set argument rescale = FALSE
   - Ploting response and suitability
  
  > plotResponse(sp4)
  > 
  > sp4 <- convertToPA(sp4)
     --- Generating a random value of beta for the logistic conversion
  
  
     --- Determing species.prevalence automatically according to alpha and beta
  
  
     Logistic conversion finished:
                
  - beta = 0.030905068707575
  - alpha = -0.05
  - species prevalence =0.4
  
  
  > plotSuitabilityToProba(sp4)
  > 
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold")
     --- Generating a random value of beta for the threshold conversion
  
  
     Threshold conversion finished:
                
  - cutoff = 0.777611406190597
  - species prevalence =0.008
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    beta = 0.5)
     Threshold conversion finished:
                
  - cutoff = 0.5
  - species prevalence =0.0218
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    beta = 0)
     Threshold conversion finished:
                
  - cutoff = 0
  - species prevalence =0.9573
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    beta = 1)
     Threshold conversion finished:
                
  - cutoff = 1
  - species prevalence =0
  
  
  Warning message:
  In convertToPA(sp4, PA.method = "threshold", beta = 1) :
    beta is higher than all values in your suitability raster. 
                  The species will most likely be absent everywhere
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    beta = "random")
     --- Generating a random value of beta for the threshold conversion
  
  
     Threshold conversion finished:
                
  - cutoff = 0.843409294406724
  - species prevalence =0.0048
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    species.prevalence = .2)
     Threshold conversion finished:
                
  - cutoff = 3.43087702980745e-05
  - species prevalence =0.2
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    species.prevalence = .02)
     Threshold conversion finished:
                
  - cutoff = 0.540984305121899
  - species prevalence =0.02
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    species.prevalence = .9)
     Threshold conversion finished:
                
  - cutoff = 6.09025834272775e-235
  - species prevalence =0.9
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "threshold",
  +                    species.prevalence = .99)
     Threshold conversion finished:
                
  - cutoff = 0
  - species prevalence =0.9573
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = "random",
  +                    a = NULL,
  +                    b = NULL,
  +                    species.prevalence = .99)
     --- Determing beta automatically according to alpha and species.prevalence
  
  
     Logistic conversion finished:
                
  - beta = -0.2256428290139
  - alpha = -0.05
  - species prevalence =0.9899
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = "random",
  +                    a = NULL,
  +                    b = NULL,
  +                    species.prevalence = .5)
     --- Determing beta automatically according to alpha and species.prevalence
  
  
     Logistic conversion finished:
                
  - beta = 0.00923968480875886
  - alpha = -0.05
  - species prevalence =0.5015
  
  
  > plotSuitabilityToProba(sp4)
  > sp4 <- convertToPA(sp4,
  +                    PA.method = "probability",
  +                    prob.method = "logistic",
  +                    beta = .5,
  +                    a = NULL,
  +                    b = NULL)
     --- Determing species.prevalence automatically according to alpha and beta
  
  
     Logistic conversion finished:
                
  - beta = 0.5
  - alpha = -0.05
  - species prevalence =0.0221
  
  
  > plotSuitabilityToProba(sp4)
  > 
  > 
  > for(i in 1:100){
  +   sp5 <- generateRandomSp(env)
  + }
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.995995995995996
  - alpha = -0.1
  - species prevalence =0.0045
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.768768768768769
  - alpha = -0.1
  - species prevalence =0.0905
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.316316316316316
  - alpha = -0.1
  - species prevalence =0.5972
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.722722722722723
  - alpha = -0.1
  - species prevalence =0.1156
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.235235235235235
  - alpha = -0.1
  - species prevalence =0.52
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.690690690690691
  - alpha = -0.1
  - species prevalence =0.152
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.704704704704705
  - alpha = -0.1
  - species prevalence =0.1678
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.426426426426426
  - alpha = -0.1
  - species prevalence =0.602
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.264264264264264
  - alpha = -0.1
  - species prevalence =0.5987
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.18018018018018
  - alpha = -0.1
  - species prevalence =0.1717
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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.636636636636637
  - alpha = -0.1
  - species prevalence =0.1892
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - 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
  - alpha = -0.1
  - species prevalence =0.8705
  
  
   - Determining species' response to predictor variables
  
   - Calculating species suitability
  
  Generating virtual species environmental suitability...
  
   - The response to each variable was rescaled between 0 and 1. To
              disable, set argument rescale.each.response = FALSE
  
   - The final environmental suitability was rescaled between 0 and 1. To disable, set argument rescale = FALSE
  
   - Converting into Presence - Absence
  
  Error in seq.default(min_p, max_p, length = 1000) : 
    'from' must be a finite number
  Calls: generateRandomSp -> convertToPA -> sample -> seq -> seq.default
  Execution halted