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

> ### Name: SpeciesMix
> ### Title: Fit finite mixture models to species distributions
> ### Aliases: SpeciesMix
> ### Keywords: misc
> 
> ### ** Examples
> 
> G <-4
> S <- 50
> theta <- matrix(c(-9,35,-32,0,0.7,0,-16,23,-8.2,-3,-0.6,0.8),4,3,byrow=TRUE)
> dat <- data.frame(y=rep(1,200),x=runif(200,0,2.5),z=rnorm(200,10,2))
> dat <- data.frame(dat,x.sq=dat$x^2)
> dat1 <- artificial.data(y~1+x+x.sq,dat,theta,S)
> fm4 <- SpeciesMix(obs~1+x+x.sq,dat1$pa,dat,G=4,em.prefit=TRUE,em.refit=1,est.var=TRUE)
Fitting Group 4 
Iteration | LogL 
1      |  -6009.394 
2      |  -4540.395 
3      |  -4433.871 
initial  value 4433.871314 
iter  10 value 3959.166846
iter  20 value 3832.497287
final  value 3795.236914 
converged
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
SpeciesMix
 --- call from context --- 
SpeciesMix.bernoulli(sp.form, sp.data, covar.data, G, pars, em.prefit, 
    em.steps, em.refit, est.var, residuals, trace, r1 = FALSE)
 --- call from argument --- 
if (class(fmM.out$covar) != "try-error") {
    tmp <- sqrt(diag(fmM.out$covar))
    tmp <- tmp[(G):length(tmp)]
    fmM.out$se <- matrix(tmp, G, ncol(fmM.out$coef))
    colnames(fmM.out$se) <- colnames(fmM.out$coef)
    rownames(fmM.out$se) <- rownames(fmM.out$coef)
}
 --- R stacktrace ---
where 1: SpeciesMix.bernoulli(sp.form, sp.data, covar.data, G, pars, em.prefit, 
    em.steps, em.refit, est.var, residuals, trace, r1 = FALSE)
where 2: SpeciesMix(obs ~ 1 + x + x.sq, dat1$pa, dat, G = 4, em.prefit = TRUE, 
    em.refit = 1, est.var = TRUE)

 --- value of length: 2 type: logical ---
[1] TRUE TRUE
 --- function from context --- 
function (sp.form, sp.data, covar.data, G = 2, pars = NA, em.prefit = TRUE, 
    em.steps = 4, em.refit = 1, est.var = FALSE, residuals = FALSE, 
    trace = TRUE, r1 = FALSE) 
{
    t.covar.data <- covar.data
    t.sp.data <- sp.data
    sp.form <- update.formula(sp.form, obs ~ 1 + .)
    if (em.prefit | G == 1) {
        prefit <- SpeciesMix.em(sp.form, sp.data, covar.data, 
            G, ite.max = em.steps, em.refit = em.refit, r1)
        pars <- c(additive.logistic(prefit$pi, T)[1:(G - 1)], 
            unlist(prefit$coef))
    }
    S <- dim(sp.data)[2]
    if (is.null(colnames(sp.data))) {
        sp.name <- 1:S
    }
    else {
        sp.name <- colnames(sp.data)
    }
    n <- dim(sp.data)[1]
    sp <- rep(sp.name, each = n)
    if (G == 1) 
        return(prefit)
    var.names <- colnames(covar.data)
    covar.data <- data.frame(kronecker(rep(1, S), as.matrix(covar.data)))
    names(covar.data) <- var.names
    sp.data <- as.data.frame(sp.data)
    data <- data.frame(obs = as.numeric(unlist(sp.data)), covar.data)
    names(data)[1] <- as.character(sp.form)[2]
    fmM.out <- fitmix.cpp(sp.form, data, sp, G, pars = pars, 
        calc.hes = est.var, r1)
    while (fmM.out$logl == 0) {
        prefit <- SpeciesMix.em(sp.form, t.sp.data, t.covar.data, 
            G, ite.max = em.steps, em.refit = 1, r1)
        pars <- c(additive.logistic(prefit$pi, T)[1:(G - 1)], 
            unlist(prefit$coef))
        fmM.out <- fitmix.cpp(sp.form, data, sp, G, pars = pars, 
            calc.hes = est.var, r1)
    }
    rownames(fmM.out$tau) <- sp.name
    fmM.out$se <- NA
    if (est.var) {
        fmM.out$covar <- try(solve(fmM.out$hessian))
        if (class(fmM.out$covar) != "try-error") {
            tmp <- sqrt(diag(fmM.out$covar))
            tmp <- tmp[(G):length(tmp)]
            fmM.out$se <- matrix(tmp, G, ncol(fmM.out$coef))
            colnames(fmM.out$se) <- colnames(fmM.out$coef)
            rownames(fmM.out$se) <- rownames(fmM.out$coef)
        }
    }
    if (residuals) 
        fmM.out$residuals <- mix.residuals(fmM.out, sp.form, 
            data, sp)
    fmM.out$formula <- sp.form
    class(fmM.out) <- c("archetype", "bernoulli")
    fmM.out
}
<bytecode: 0x3521a00>
<environment: namespace:SpeciesMix>
 --- function search by body ---
Function SpeciesMix.bernoulli in namespace SpeciesMix has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(fmM.out$covar) != "try-error") { : 
  the condition has length > 1
Calls: SpeciesMix -> SpeciesMix.bernoulli
Execution halted