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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: PCM
> ### Title: Create a phylogenetic comparative model object
> ### Aliases: PCM
> 
> ### ** Examples
> 
> # a Brownian motion model with one regime
> modelBM <- PCM(model = "BM", k = 2)
> # print the model
> modelBM
Brownian motion model
S3 class: BM, GaussianPCM, PCM; k=2; p=8; regimes: 1. Parameters/sub-models:
X0 (VectorParameter, _Global, numeric; trait values at the root):
[1] 0 0
Sigma_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the unit-time variance rate):
, , 1

     [,1] [,2]
[1,]    0    0
[2,]    0    0

Sigmae_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the non-heritable variance or the variance of the measurement error):
, , 1

     [,1] [,2]
[1,]    0    0
[2,]    0    0

 
> 
> # a BM model with two regimes
> modelBM.ab <- PCM("BM", k = 2, regimes = c("a", "b"))
> modelBM.ab
Brownian motion model
S3 class: BM, GaussianPCM, PCM; k=2; p=14; regimes: a, b. Parameters/sub-models:
X0 (VectorParameter, _Global, numeric; trait values at the root):
[1] 0 0
Sigma_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the unit-time variance rate):
, , a

     [,1] [,2]
[1,]    0    0
[2,]    0    0

, , b

     [,1] [,2]
[1,]    0    0
[2,]    0    0

Sigmae_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the non-heritable variance or the variance of the measurement error):
, , a

     [,1] [,2]
[1,]    0    0
[2,]    0    0

, , b

     [,1] [,2]
[1,]    0    0
[2,]    0    0

 
> 
> # print a single parameter of the model (in this case, the root value)
> modelBM.ab$X0
[1] 0 0
attr(,"class")
[1] "VectorParameter" "_Global"         "numeric"        
attr(,"description")
[1] "trait values at the root"
> 
> # assign a value to this parameter (note that the brackets [] are necessary
> # to preserve  the parameter attributes):
> modelBM.ab$X0[] <- c(5, 2)
> 
> PCMNumTraits(modelBM)
[1] 2
> PCMNumRegimes(modelBM)
[1] 1
> PCMNumRegimes(modelBM.ab)
[1] 2
> 
> # number of numerical parameters in the model
> PCMParamCount(modelBM)
[1] 8
> 
> # Get a vector representation of all parameters in the model
> PCMParamGetShortVector(modelBM)
[1] 0 0 0 0 0 0 0 0
> 
> # Limits for the model parameters:
> lowerLimit <- PCMParamLowerLimit(modelBM)
> upperLimit <- PCMParamUpperLimit(modelBM)
> 
> # assign the model parameters at random: this will use uniform distribution
> # with boundaries specified by PCMParamLowerLimit and PCMParamUpperLimit
> # We do this in two steps:
> # 1. First we generate a random vector. Note the length of the vector equals PCMParamCount(modelBM)
> randomParams <- PCMParamRandomVecParams(modelBM, PCMNumTraits(modelBM), PCMNumRegimes(modelBM))
> randomParams
          [,1]      [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
[1,] -4.689827 -2.557522 5.728534 8.164156 2.016819 8.983897 8.893505 6.607978
> # 2. Then we load this random vector into the model.
> PCMParamLoadOrStore(modelBM, randomParams, 0, PCMNumTraits(modelBM), PCMNumRegimes(modelBM), TRUE)
[1] 8
> 
> print(modelBM)
Brownian motion model
S3 class: BM, GaussianPCM, PCM; k=2; p=8; regimes: 1. Parameters/sub-models:
X0 (VectorParameter, _Global, numeric; trait values at the root):
[1] -4.689827 -2.557522
Sigma_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the unit-time variance rate):
, , 1

         [,1]     [,2]
[1,] 5.728534 8.164156
[2,] 0.000000 2.016819

Sigmae_x (MatrixParameter, _UpperTriangularWithDiagonal, _WithNonNegativeDiagonal; factor of the non-heritable variance or the variance of the measurement error):
, , 1

         [,1]     [,2]
[1,] 8.983897 8.893505
[2,] 0.000000 6.607978

 
> 
> PCMParamGetShortVector(modelBM)
[1] -4.689827 -2.557522  5.728534  8.164156  2.016819  8.983897  8.893505
[8]  6.607978
> 
> # generate a random phylogenetic tree of 10 tips
> tree <- ape::rtree(10)
> 
> #simulate the model on the tree
> traitValues <- PCMSim(tree, modelBM, X0 = modelBM$X0)
> 
> # calculate the likelihood for the model parameters, given the tree and the trait values
> PCMLik(traitValues, tree, modelBM)
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
PCMBase
 --- call from context --- 
PCMLik.GaussianPCM(traitValues, tree, modelBM)
 --- call from argument --- 
if (class(loglik) == "try-error") {
    err <- paste0("GaussianPCM.R:PCMLik:: There was a problem calculating loglik from X0 and the coefficients L,m,r. ", 
        "X0=", toString(X0), "L0=", toString(L0), "; m0=", toString(m0), 
        "; r0=", r0, ". Error message from call to X0 %*% L0 %*% X0 + m0 %*% X0 + r0:", 
        loglik, "\n")
    errL <- PCMParseErrorMessage(err)
    if (getOption("PCMBase.Raise.Lik.Errors", TRUE)) {
        if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
            warning(err)
        }
        else {
            stop(err)
        }
    }
    attr(value.NA, "X0") <- X0
    attr(value.NA, "error") <- errL
    return(value.NA)
}
 --- R stacktrace ---
where 1: PCMLik.GaussianPCM(traitValues, tree, modelBM)
where 2: PCMLik(traitValues, tree, modelBM)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (X, tree, model, SE = matrix(0, PCMNumTraits(model), 
    PCMTreeNumTips(tree)), metaI = PCMInfo(X = X, tree = tree, 
    model = model, SE = SE, verbose = verbose), log = TRUE, verbose = FALSE) 
{
    if (is.Transformable(model)) {
        model <- PCMApplyTransformation(model)
    }
    if (is.function(metaI)) {
        metaI <- metaI(X = X, tree = tree, model = model, SE = SE, 
            verbose = verbose)
    }
    value.NA <- getOption("PCMBase.Value.NA", as.double(NA))
    PCMLmr <- try(PCMLmr(X = X, tree = tree, model = model, SE = SE, 
        metaI = metaI, verbose = verbose, root.only = TRUE), 
        silent = TRUE)
    if (class(PCMLmr) == "try-error") {
        errL <- PCMParseErrorMessage(PCMLmr)
        if (is.null(errL)) {
            err <- paste0("GaussianPCM.R:PCMLik:: There was a problem calculating the coefficients L,m,r. Error message from call to PCMLmr: ", 
                PCMLmr, "; print(model):", do.call(paste, c(as.list(capture.output(print(model))), 
                  list(sep = "\n"))))
            errL <- PCMParseErrorMessage(err)
        }
        else {
            err <- PCMLmr
        }
        if (getOption("PCMBase.Raise.Lik.Errors", TRUE)) {
            if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
                warning(err)
            }
            else {
                stop(err)
            }
        }
        k0 <- metaI$pc[, metaI$N + 1L]
        X0 <- rep(NaN, metaI$k)
        X0[k0] <- model$X0[k0]
        attr(value.NA, "X0") <- X0
        attr(value.NA, "error") <- errL
        return(value.NA)
    }
    else if (is.list(PCMLmr)) {
        L0 <- as.matrix(PCMLmr$L)
        m0 <- PCMLmr$m
        r0 <- PCMLmr$r
        k0 <- metaI$pc[, metaI$N + 1L]
        if (is.null(L0) | is.null(m0) | is.null(r0)) {
            err <- paste0("GaussianPCM.R:PCMLik:: The list returned by PCMLmr did not contain elements 'L', 'm' and 'r'.")
            if (!getOption("PCMBase.Ignore.Lmr.Errors", FALSE)) {
                if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
                  warning(err)
                }
                else {
                  stop(err)
                }
            }
            errL <- PCMParseErrorMessage(err)
            k0 <- metaI$pc[, metaI$N + 1L]
            X0 <- rep(NaN, metaI$k)
            X0[k0] <- model$X0[k0]
            attr(value.NA, "X0") <- X0
            attr(value.NA, "error") <- errL
            return(value.NA)
        }
        if (is.null(model$X0) || isTRUE(all(is.na(model$X0)))) {
            X0 <- rep(NaN, metaI$k)
            X0[k0] <- rep(NA_real_, sum(k0))
            X0[k0] <- try(solve(a = L0[k0, k0, drop = FALSE] + 
                t(L0[k0, k0, drop = FALSE]), b = -m0[k0]), silent = TRUE)
            if (class(X0[[1]]) == "try-error") {
                err <- paste0("GaussianPCM.R:PCMLik:: There was a problem calculating X0 from L0,m0,r0. ", 
                  "L0=", toString(L0), "; m0=", toString(m0), 
                  "; r0=", r0, ". Error message:", X0[[1]], "\n")
                errL <- PCMParseErrorMessage(err)
                if (getOption("PCMBase.Raise.Lik.Errors", TRUE)) {
                  if (getOption("PCMBase.Errors.As.Warnings", 
                    TRUE)) {
                    warning(err)
                  }
                  else {
                    stop(err)
                  }
                }
                X0 <- NULL
                attr(value.NA, "X0") <- X0
                attr(value.NA, "error") <- errL
                return(value.NA)
            }
        }
        else {
            k0 <- metaI$pc[, metaI$N + 1L]
            X0 <- rep(NaN, metaI$k)
            X0[k0] <- model$X0[k0]
        }
        loglik <- try(X0[k0] %*% L0[k0, k0, drop = FALSE] %*% 
            X0[k0] + m0[k0] %*% X0[k0] + r0, silent = TRUE)
        if (class(loglik) == "try-error") {
            err <- paste0("GaussianPCM.R:PCMLik:: There was a problem calculating loglik from X0 and the coefficients L,m,r. ", 
                "X0=", toString(X0), "L0=", toString(L0), "; m0=", 
                toString(m0), "; r0=", r0, ". Error message from call to X0 %*% L0 %*% X0 + m0 %*% X0 + r0:", 
                loglik, "\n")
            errL <- PCMParseErrorMessage(err)
            if (getOption("PCMBase.Raise.Lik.Errors", TRUE)) {
                if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
                  warning(err)
                }
                else {
                  stop(err)
                }
            }
            attr(value.NA, "X0") <- X0
            attr(value.NA, "error") <- errL
            return(value.NA)
        }
        value <- try(as.vector(if (log) 
            loglik
        else exp(loglik)), silent = TRUE)
        if (class(value) == "try-error") {
            err <- paste0("GaussianPCM.R:PCMLik:: There was a problem calculating value from loglik=", 
                toString(loglik), ". Error message from call to as.vector(if(log) loglik else exp(loglik)):", 
                value, "; print(model):", do.call(paste, c(as.list(capture.output(print(model))), 
                  list(sep = "\n"))))
            errL <- PCMParseErrorMessage(err)
            if (getOption("PCMBase.Raise.Lik.Errors", TRUE)) {
                if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
                  warning(err)
                }
                else {
                  stop(err)
                }
            }
            attr(value.NA, "X0") <- X0
            attr(value.NA, "error") <- errL
            return(value.NA)
        }
        else if (is.na(value)) {
            err <- paste0("GaussianPCM.R:PCMLik:: There was a possible numerical problem, e.g. division of 0 by 0 when calculating the likelihood. value=", 
                toString(value), "; calculated loglik=", toString(loglik), 
                "; print(model):", do.call(paste, c(as.list(capture.output(print(model))), 
                  list(sep = "\n"))), ". No error message was returned from the call to PCMLmr. Check for runtime warnings.")
            errL <- PCMParseErrorMessage(err)
            if (getOption("PCMBase.Errors.As.Warnings", TRUE)) {
                warning(err)
            }
            else {
                stop(err)
            }
            attr(value.NA, "X0") <- X0
            attr(value.NA, "error") <- errL
            return(value.NA)
        }
        attr(value, "X0") <- X0
        return(value)
    }
}
<bytecode: 0x5573e66ec890>
<environment: namespace:PCMBase>
 --- function search by body ---
Function PCMLik.GaussianPCM in namespace PCMBase has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1