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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: BigVAR
> ### Title: Dimension Reduction Methods for Multivariate Time Series.
> ### Aliases: BigVAR BigVAR-package
> 
> ### ** Examples
> 
> # Fit a Basic VAR-L(3,4) on simulated data
> data(Y)
> T1=floor(nrow(Y)/3)
> T2=floor(2*nrow(Y)/3)
> m1=constructModel(Y,p=4,struct="Basic",gran=c(50,10),verbose=FALSE,T1=T1,T2=T2,IC=FALSE)
> plot(m1)
> results=cv.BigVAR(m1)
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
BigVAR
 --- call from context --- 
cv.BigVAR(m1)
 --- call from argument --- 
if (class(ZFull$Y) != "matrix") {
    ZFull$Y <- matrix(ZFull$Y, ncol = 1)
}
 --- R stacktrace ---
where 1: cv.BigVAR(m1)
where 2: cv.BigVAR(m1)

 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context --- 
Method Definition:

function (object) 
{
    p <- object@lagmax
    s1 <- 0
    Y <- object@Data
    k <- ncol(Y)
    alpha <- object@alpha
    RVAR <- object@Relaxed
    group <- object@Structure
    cvtype <- object@crossval
    intercept = object@intercept
    recursive <- object@recursive
    VARX <- object@VARX
    tol = object@tol
    window.size = object@window.size
    if (length(alpha) == 0) {
        if (length(VARX) > 0) {
            alpha <- 1/(VARX$k + 1)
        }
        else {
            alpha <- 1/(k + 1)
        }
    }
    C <- object@constvec
    if (length(alpha) > 1 & group %in% c("SparseLag", "SparseOO")) {
        dual <- TRUE
    }
    else {
        dual <- FALSE
    }
    MN <- object@Minnesota
    h <- object@horizon
    jj <- 0
    if (!"matrix" %in% class(Y)) {
        Y = matrix(Y, ncol = 1)
    }
    if (object@crossval == "Rolling") {
        T1 <- object@T1
    }
    else {
        T1 <- p + 2
    }
    T2 <- object@T2
    s <- ifelse(length(object@VARX) != 0, object@VARX$s, 0)
    if (object@ownlambdas) {
        gamm <- object@Granularity
        gran2 <- length(gamm)
    }
    ONESE <- object@ONESE
    if (object@crossval == "Rolling") {
        T1 <- T1 - max(p, s)
        T2 <- T2 - max(p, s)
    }
    if (!object@ownlambdas) {
        gran2 <- object@Granularity[2]
        gran1 <- object@Granularity[1]
    }
    if (length(VARX) != 0) {
        VARX <- TRUE
        k1 <- object@VARX$k
        s <- object@VARX$s
        if (!is.null(object@VARX$contemp)) {
            contemp <- TRUE
            s1 <- 1
        }
        else {
            contemp <- FALSE
            s1 <- 0
        }
        if (window.size == 0) {
            window.size = 0
        }
        else {
            window.size <- window.size + 1
        }
        m <- k - k1
        Y1 <- matrix(Y[, 1:k1], ncol = k1)
        X <- matrix(Y[, (ncol(Y) - m + 1):ncol(Y)], ncol = m)
        if (!object@tf) {
            trainZ <- VARXCons(Y1, X, k1, p, m, s, contemp = contemp)
        }
        else {
            trainZ <- VARXCons(matrix(0, ncol = 1, nrow = nrow(X)), 
                matrix(X, ncol = m), k = 0, p = 0, m = m, s = s, 
                contemp = contemp, oos = FALSE)
        }
        trainZ <- trainZ[2:nrow(trainZ), ]
        trainY <- matrix(Y[(max(c(p, s)) + 1):nrow(Y), 1:k1], 
            ncol = k1)
        if (group == "Lag" | group == "SparseLag") {
            jj <- groupfunVARXLG(p, k, k1, s + s1)
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2 * length(alpha))
        }
        if (group == "OwnOther" | group == "SparseOO") {
            jj <- diaggroupfunVARXLG(p, k, k1, s + s1)
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2)
        }
        if (object@ownlambdas == FALSE) {
            if (dual) {
                gamm <- .LambdaGridXDual(gran1, gran2, jj, trainY, 
                  trainZ, group, p, k1, s, m, k, MN, alpha, C, 
                  intercept, tol)
            }
            else {
                gamm <- .LambdaGridX(gran1, gran2, jj, as.matrix(trainY[1:T2, 
                  ]), trainZ[, 1:T2], group, p, k1, s + s1, m, 
                  k, MN, alpha, C, intercept, tol)
            }
        }
        beta <- array(0, dim = c(k1, k1 * p + (k - k1) * (s + 
            s1) + 1, gran2 * length(alpha)))
        if (group == "Lag") {
            jj <- groupfunVARX(p, k, k1, s + s1)
            jjcomp <- groupfunVARXcomp(p, k, k1, s + s1)
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2)
        }
        if (group == "SparseLag") {
            jj <- groupfunVARX(p, k, k1, s + s1)
            q1a <- list()
            for (i in 1:(p + s + s1)) {
                q1a[[i]] <- matrix(runif(length(jj[[i]]), -1, 
                  1), ncol = 1)
            }
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2 * length(alpha))
        }
        if (group == "OwnOther") {
            kk <- diaggroupfunVARX(p, k, k1, s + s1)
            activeset <- rep(list(rep(rep(list(0), length(kk)))), 
                gran2)
        }
        if (group == "SparseOO") {
            kk <- diaggroupfunVARX(p, k, k1, s + s1)
            activeset <- rep(list(rep(rep(list(0), length(kk)))), 
                gran2 * length(alpha))
            q1a <- list()
            for (i in 1:(2 * p + s + s1)) {
                q1a[[i]] <- matrix(runif(length(jj[[i]]), -1, 
                  1), ncol = 1)
            }
        }
    }
    else {
        contemp <- FALSE
        if (group == "Lag" | group == "SparseLag") {
            jj <- .groupfun(p, k)
        }
        else {
            jj <- .lfunction3(p, k)
        }
        Z1 <- VARXCons(Y, matrix(0, nrow = nrow(Y)), k, p, 0, 
            0)
        trainZ <- Z1[2:nrow(Z1), ]
        trainY <- matrix(Y[(p + 1):nrow(Y), ], ncol = k)
        GY <- matrix(trainY[1:T2, ], ncol = k)
        GZ <- trainZ[, 1:T2]
        if (object@ownlambdas == FALSE) {
            if (dual) {
                gamm <- .LambdaGridEDual(gran1, gran2, jj, GY, 
                  GZ, group, p, k, MN, alpha, C, intercept, tol)
            }
            else {
                if (group != "BGR") {
                  gamm <- .LambdaGridE(gran1, gran2, jj, GY, 
                    GZ, group, p, k, MN, alpha, C, intercept, 
                    tol)
                }
                else {
                  gamm <- seq(1, 5, by = 0.025)
                  gamm <- gamm * sqrt(k * p)
                }
            }
        }
        VARX <- FALSE
        k1 <- k
        s <- 0
        if (group == "Lag") {
            jj <- .groupfuncpp(p, k)
            jjcomp <- .groupfuncomp(p, k)
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2)
            k1 = k
        }
        if (group == "SparseLag") {
            jj <- .groupfuncpp(p, k)
            q1a <- list()
            for (i in 1:p) {
                q1a[[i]] <- matrix(runif(k, -1, 1), ncol = 1)
            }
            activeset <- rep(list(rep(rep(list(0), length(jj)))), 
                gran2 * length(alpha))
        }
        if (group == "OwnOther") {
            kk <- .lfunction3cpp(p, k)
            activeset <- rep(list(rep(rep(list(0), length(kk)))), 
                gran2)
        }
        if (group == "SparseOO") {
            kk <- .lfunction3cpp(p, k)
            jjcomp <- .lfunctioncomp(p, k)
            jj <- .lfunction3(p, k)
            activeset <- rep(list(rep(rep(list(0), length(kk)))), 
                gran2 * length(alpha))
            q1a <- list()
            for (i in 1:(2 * p)) {
                q1a[[i]] <- matrix(runif(length(kk[[i]]), -1, 
                  1), ncol = 1)
            }
        }
        beta <- array(0, dim = c(k, k * p + 1, gran2 * length(alpha)))
    }
    h <- object@horizon
    verbose <- object@verbose
    ZFull <- list()
    if (!is.matrix(trainZ)) {
        trainZ <- matrix(trainZ, ncol = 1)
    }
    if (!is.matrix(trainY)) {
        trainY <- matrix(trainY, ncol = 1)
    }
    ZFull$Z <- trainZ
    ZFull$Y <- trainY
    T <- nrow(trainY)
    if (object@ownlambdas) {
        gamm <- object@Granularity
    }
    if (group == "Tapered") {
        palpha <- seq(0, 1, length = 10)
        palpha <- rev(palpha)
        gran2 <- length(gamm) * length(palpha)
        beta <- array(0, dim = c(k, k * p + 1, gran2))
    }
    if (class(ZFull$Y) != "matrix") {
        ZFull$Y <- matrix(ZFull$Y, ncol = 1)
    }
    if (!dual) {
        MSFE <- matrix(0, nrow = T2 - T1 + 1, ncol = gran2)
    }
    else {
        nalpha <- length(alpha)
        MSFE <- matrix(0, nrow = T2 - T1 + 1, ncol = gran2 * 
            nalpha)
    }
    if (verbose) {
        pb <- txtProgressBar(min = T1, max = T2, style = 3)
        cat("Cross-Validation Stage:", group)
    }
    YT <- Y[1:T2, ]
    for (v in (T1 - h + 1):T2) {
        if (cvtype == "Rolling") {
            if (v + h - 1 > T2) {
                break
            }
            if (h > 1 & !recursive) {
                if (window.size != 0) {
                  ws1 <- max(c(v - window.size - h, 1))
                  trainY <- ZFull$Y[(ws1 + h):(v - 1), ]
                  trainZ <- ZFull$Z[, (ws1 + h):(v - h)]
                }
                else {
                  trainY <- ZFull$Y[(h):(v - 1), ]
                  trainZ <- ZFull$Z[, 1:(v - h)]
                }
            }
            else {
                if (window.size != 0) {
                  ws1 <- max(c(v - window.size, 1))
                  trainY <- ZFull$Y[(ws1):(v - 1), ]
                  trainZ <- ZFull$Z[, (ws1):(v - 1)]
                }
                else {
                  trainY <- ZFull$Y[(1):(v - 1), ]
                  trainZ <- ZFull$Z[, (1):(v - 1)]
                }
            }
        }
        else {
            if (VARX) {
                YT2 <- YT[-v, ]
                Y1 <- matrix(YT2[, 1:k1], ncol = k1)
                X <- matrix(YT2[, (ncol(YT2) - m + 1):ncol(YT2)], 
                  ncol = m)
                trainZ <- VARXCons(Y1, X, k1, p, m, s, contemp = contemp)
                trainZ <- trainZ[2:nrow(trainZ), ]
                trainY <- matrix(YT2[(max(c(p, s)) + 1):nrow(YT2), 
                  1:k1], ncol = k1)
            }
            else {
                YT2 <- YT[-v, ]
                Z1 <- VARXCons(YT2, matrix(0, nrow = nrow(YT2)), 
                  k, p, 0, 0)
                trainZ <- Z1[2:nrow(Z1), ]
                trainY <- matrix(YT2[(p + 1):nrow(YT2), ], ncol = k)
            }
        }
        if (group == "Basic") {
            if (VARX) {
                beta <- .lassoVARFistX(beta, trainZ, trainY, 
                  gamm, tol, p, MN, k, k1, s + s1, m, C, intercept)
            }
            else {
                beta <- .lassoVARFist(beta, trainZ, trainY, gamm, 
                  tol, p, MN, C, intercept)
            }
        }
        if (group == "Lag") {
            GG <- .GroupLassoVAR1(beta, jj, jjcomp, trainY, trainZ, 
                gamm, activeset, tol, p, MN, k, k1, s + s1, C, 
                intercept)
            beta <- GG$beta
            activeset <- GG$active
        }
        if (group == "SparseLag") {
            if (VARX) {
                if (!dual) {
                  GG <- .SparseGroupLassoVARX(beta, jj, trainY, 
                    trainZ, gamm, alpha, INIactive = activeset, 
                    tol, q1a, p, MN, k, s + s1, k1, C, intercept)
                }
                else {
                  GG <- .SparseGroupLassoVARXDual(beta, jj, trainY, 
                    trainZ, gamm, alpha, INIactive = activeset, 
                    tol, q1a, p, MN, k, s + s1, k1, C, intercept)
                }
            }
            else {
                if (!dual) {
                  GG <- .SparseGroupLassoVAR(beta, jj, trainY, 
                    trainZ, gamm, alpha, INIactive = activeset, 
                    tol, q1a, p, MN, C, intercept)
                }
                else {
                  GG <- .SparseGroupLassoVARDual(beta, jj, trainY, 
                    trainZ, gamm, alpha, INIactive = activeset, 
                    tol, q1a, p, MN, C, intercept)
                }
            }
            beta <- GG$beta
            activeset <- GG$active
            q1a <- GG$q1
        }
        if (group == "OwnOther") {
            if (VARX) {
                GG <- .GroupLassoOOX(beta, kk, trainY, trainZ, 
                  gamm, activeset, tol, p, MN, k, k1, s + s1, 
                  C, intercept)
            }
            else {
                GG <- .GroupLassoOO(beta, kk, trainY, trainZ, 
                  gamm, activeset, tol, p, MN, C, intercept)
            }
            beta <- GG$beta
            activeset <- GG$active
        }
        if (group == "SparseOO") {
            if (VARX) {
                GG <- .SparseGroupLassoVAROOX(beta, kk, trainY, 
                  trainZ, gamm, alpha, INIactive = activeset, 
                  tol, p, MN, k1, s + s1, k, dual, C, intercept)
            }
            else {
                GG <- .SparseGroupLassoVAROO(beta, kk, trainY, 
                  trainZ, gamm, alpha, INIactive = activeset, 
                  tol, q1a, p, MN, dual, C, intercept)
                q1a <- GG$q1
            }
            beta <- GG$beta
            activeset <- GG$active
        }
        if (group == "Tapered") {
            beta <- .lassoVARTL(beta, trainZ, trainY, gamm, tol, 
                p, MN, palpha, C, intercept)
        }
        if (group == "EFX") {
            beta <- .EFVARX(beta, trainY, trainZ, gamm, tol, 
                MN, k1, s, m, p, C, intercept)
        }
        if (group == "HVARC") {
            beta <- .HVARCAlg(beta, trainY, trainZ, gamm, tol, 
                p, MN, C, intercept)
        }
        if (group == "HVAROO") {
            beta <- .HVAROOAlg(beta, trainY, trainZ, gamm, tol, 
                p, MN, C, intercept)
        }
        if (group == "HVARELEM") {
            beta <- .HVARElemAlg(beta, trainY, trainZ, gamm, 
                tol, p, MN, C, intercept)
        }
        eZ <- c(1, ZFull$Z[, v])
        if (group != "BGR") {
            if (!dual) {
                for (ii in 1:gran2) {
                  if (RVAR) {
                    beta[, , ii] <- RelaxedLS(cbind(t(trainZ), 
                      trainY), beta[, , ii], k, p, k1, s + s1)
                  }
                  if (MN) {
                    pred <- beta[, 2:dim(beta)[2], ii] %*% eZ[2:length(eZ)]
                    if (h > 1 & recursive) {
                      pred <- matrix(pred, nrow = 1)
                      pred <- predictMS(pred, trainY, h - 1, 
                        beta[, 2:dim(beta)[2], ii], p, MN)
                    }
                    MSFE[v - (T1 - h), ii] <- norm2(ZFull$Y[v + 
                      h - 1, 1:k1] - pred)^2
                    diag(beta[, 2:(k1 + 1), ii]) <- diag(beta[, 
                      2:(k1 + 1), ii]) - C
                  }
                  else {
                    if (object@crossval == "Rolling") {
                      pred <- beta[, , ii] %*% eZ
                      if (h > 1 & recursive) {
                        pred <- matrix(pred, nrow = 1)
                        pred <- predictMS(pred, trainY, h - 1, 
                          beta[, , ii], p)
                      }
                      MSFE[v - (T1 - h), ii] <- norm2(ZFull$Y[v + 
                        h - 1, 1:k1] - pred)^2
                    }
                    else {
                      if (VARX) {
                        eZ <- VARXCons(matrix(Y[(v - p):(v), 
                          1:k1], ncol = k1), Y[(v - p):(v), (ncol(Y) - 
                          m + 1):(ncol(Y))], k1, p, m, s, contemp = contemp)
                        pred <- beta[, , ii] %*% eZ
                      }
                      else {
                        eZ <- VARXCons(Y[(v - p):(v), 1:k1], 
                          matrix(0, nrow = length((v - p):v)), 
                          k1, p, 0, 0)
                        pred <- beta[, , ii] %*% eZ
                      }
                      MSFE[v - (T1 - h), ii] <- norm2(Y[v + h - 
                        1, 1:k1] - pred)^2
                    }
                  }
                }
            }
            else {
                for (ii in 1:gran2) {
                  for (jj in 1:length(alpha)) {
                    if (RVAR) {
                      beta[, , (ii - 1) * nalpha + jj] <- RelaxedLS(cbind(t(trainZ), 
                        trainY), beta[, , (ii - 1) * nalpha + 
                        jj], k, p, k1, s + s1)
                    }
                    if (MN) {
                      if (!intercept) {
                        pred <- beta[, 2:dim(beta)[2], (ii - 
                          1) * nalpha + jj] %*% eZ[2:length(eZ)]
                      }
                      else {
                        pred <- beta[, , (ii - 1) * nalpha + 
                          jj] %*% eZ
                      }
                      if (h > 1 & recursive) {
                        pred <- matrix(pred, nrow = 1)
                        pred <- predictMS(pred, trainY, h - 1, 
                          beta[, 2:dim(beta)[2], (ii - 1) * nalpha + 
                            jj], p, MN)
                      }
                      MSFE[v - (T1 - h), (ii - 1) * nalpha + 
                        jj] <- norm2(ZFull$Y[v + h - 1, 1:k1] - 
                        beta[, 2:dim(beta)[2], (ii - 1) * nalpha + 
                          jj] %*% eZ[2:length(eZ)])^2
                    }
                    else {
                      pred <- beta[, , (ii - 1) * nalpha + jj] %*% 
                        eZ
                      if (h > 1 & recursive) {
                        pred <- matrix(pred, nrow = 1)
                        pred <- predictMS(pred, trainY, h - 1, 
                          beta[, , (ii - 1) * nalpha + jj], p)
                      }
                      if (object@crossval == "Rolling") {
                        MSFE[v - (T1 - h), (ii - 1) * nalpha + 
                          jj] <- norm2(ZFull$Y[v + h - 1, 1:k1] - 
                          beta[, , (ii - 1) * nalpha + jj] %*% 
                            eZ)^2
                        err <- norm2(ZFull$Y[v, 1:k1] - beta[, 
                          , ii] %*% eZ)^2
                      }
                      else {
                        if (VARX) {
                          eZ <- VARXCons(matrix(Y[(v - p):(v), 
                            1:k1], ncol = k1), Y[(v - p):(v), 
                            (ncol(Y) - m + 1):(ncol(Y))], k1, 
                            p, m, s, contemp = contemp)
                        }
                        else {
                          eZ <- VARXCons(Y[(v - p):(v), 1:k1], 
                            matrix(0, nrow = length((v - p):v)), 
                            k1, p, 0, 0)
                        }
                        MSFE[v - (T1 - h), (ii - 1) * nalpha + 
                          jj] <- norm2(Y[v, 1:k1] - beta[, , 
                          (ii - 1) * nalpha + jj] %*% eZ)^2
                      }
                    }
                  }
                }
            }
        }
        else {
            for (ii in 1:ncol(MSFE)) {
                MSFE[v - (T1 - h), ii] <- norm2(Y[v + h - 1, 
                  1:k1] - beta[, , ii])^2
            }
        }
        if (verbose) {
            setTxtProgressBar(pb, v)
        }
    }
    if (group == "Tapered") {
        indopt <- which.min(colMeans(MSFE))
        if (indopt < length(gamm)) {
            alphaind <- 1
            alphaopt <- palpha[1]
        }
        else {
            alphaopt <- palpha[floor(indopt/length(gamm))]
            alphaind <- floor(indopt/length(gamm))
        }
        if (alphaind == 1) {
            gamopt <- gamm[indopt]
        }
        else if (indopt%%length(gamm) == 0) {
            gamopt <- gamm[length(gamm)]
        }
        else {
            gamind <- indopt - length(gamm) * alphaind
            gamopt <- gamm[gamind]
        }
        palpha <- alphaopt
        optind <- indopt
    }
    if (ONESE & !dual) {
        MSFE2 <- MSFE
        G2 <- colMeans(na.omit(MSFE2))
        G3 <- sd(na.omit(MSFE2))/sqrt(nrow(na.omit(MSFE2)))
        optind <- min(which(G2 < (min(G2) + G3)))
        gamopt <- gamm[optind]
    }
    else {
        if (group != "Tapered" & !dual) {
            optind <- max(which(colMeans(na.omit(MSFE)) == min(colMeans(na.omit(MSFE)))))
            gamopt <- gamm[optind]
        }
        else if (dual) {
            if (!ONESE) {
                optind <- max(which(colMeans(na.omit(MSFE)) == 
                  min(colMeans(na.omit(MSFE)))))
                inds <- findind(optind, gamm[, 1], alpha)
            }
            else {
                G2 <- colMeans(na.omit(MSFE))
                G3 <- sd(na.omit(MSFE))/sqrt(nrow(na.omit(MSFE)))
                optind <- min(which(G2 < (min(G2) + G3)))
                inds <- findind(optind, gamm[, 1], alpha)
            }
            gamopt <- gamm[inds[1], inds[2]]
            gamm <- gamm[, inds[2]]
            alphaopt <- alpha[inds[2]]
            optind <- inds
        }
    }
    if (!dual) {
        alphaopt <- alpha
    }
    if (VARX) {
        OOSEval <- .BigVAREVALX(ZFull, gamopt, k, p, group, h, 
            MN, verbose, RVAR, palpha, T2, T, k1, s, m, contemp, 
            alphaopt, C, intercept, tol, window.size)
    }
    else {
        OOSEval <- .BigVAREVAL(ZFull, gamopt, k, p, group, h, 
            MN, verbose, RVAR, palpha, T2, T, alphaopt, recursive, 
            C, intercept, tol, window.size)
    }
    MSFEOOSAgg <- na.omit(OOSEval$MSFE)
    betaPred <- OOSEval$betaPred
    betaArray <- OOSEval$betaArray
    preds <- OOSEval$predictions
    Y <- object@Data
    if (VARX) {
        if (contemp) {
            OOS <- FALSE
        }
        else {
            OOS <- TRUE
        }
        if (!object@tf) {
            Zvals <- VARXCons(matrix(Y[, 1:k1], ncol = k1), matrix(Y[, 
                (ncol(Y) - m + 1):ncol(Y)], ncol = m), k1, p, 
                m, s, oos = OOS, contemp = contemp)
        }
        else {
            Zvals <- VARXCons(matrix(0, ncol = 1, nrow = nrow(Y)), 
                matrix(Y[, (ncol(Y) - m + 1):ncol(Y)], ncol = m), 
                0, 0, m, s, oos = FALSE, contemp = contemp)
        }
    }
    else {
        m <- 0
        s <- 0
        Zvals <- VARXCons(matrix(Y[, 1:k1], ncol = k1), matrix(0, 
            nrow = nrow(Y)), k1, p, m, s, oos = TRUE)
    }
    Zvals <- matrix(Zvals[, ncol(Zvals)], ncol = 1)
    if (ncol(Y) == 1 | k1 == 1) {
        betaPred <- matrix(betaPred, nrow = 1)
    }
    lagmatrix <- rbind(rep(1, ncol(ZFull$Z)), ZFull$Z)
    fitted <- t(betaPred %*% lagmatrix)
    resids <- ((ZFull$Y) - fitted)
    MSFEOOS <- mean(na.omit(MSFEOOSAgg))
    seoos <- sd(na.omit(MSFEOOSAgg))/sqrt(length(na.omit(MSFEOOSAgg)))
    if (!VARX) {
        k1 <- k
    }
    meanbench <- .evalMean(ZFull$Y[, 1:k1], T2, T, h = h)
    RWbench <- .evalRW(ZFull$Y[, 1:k1], T2, T, h = h)
    if (object@ic == FALSE | object@tf) {
        AICbench <- list()
        AICbench$Mean <- as.double(NA)
        AICbench$SD <- as.double(NA)
        AICbench$preds <- as.matrix(NA)
        AICbench$pvec <- as.double(NA)
        AICbench$svec <- as.double(NA)
        BICbench <- list()
        BICbench$Mean <- as.double(NA)
        BICbench$SD <- as.double(NA)
        BICbench$preds <- as.matrix(NA)
        BICbench$pvec <- as.double(NA)
        BICbench$svec <- as.double(NA)
    }
    else {
        if (!VARX) {
            X <- matrix(0, nrow = nrow(Y), ncol = k)
            AICbench1 <- VARXForecastEval(matrix(ZFull$Y, ncol = k), 
                X, p, 0, T2, T, "AIC", h)
            AICbench <- list()
            AICbench$Mean <- mean(AICbench1$MSFE)
            AICbench$SD <- sd(AICbench1$MSFE)/sqrt(length(AICbench1$MSFE))
            AICbench$preds <- AICbench1$pred
            AICbench$pvec <- AICbench1$p
            AICbench$svec <- AICbench1$s
            BICbench1 <- VARXForecastEval(matrix(ZFull$Y, ncol = k), 
                X, p, 0, T2, T, "BIC", h)
            BICbench <- list()
            BICbench$Mean <- mean(BICbench1$MSFE)
            BICbench$SD <- sd(BICbench1$MSFE)/sqrt(length(BICbench1$MSFE))
            BICbench$preds <- BICbench1$pred
            BICbench$pvec <- BICbench1$p
            BICbench$svec <- BICbench1$s
        }
        else {
            offset <- max(c(p, s))
            X <- matrix(Y[(offset + 1):nrow(Y), (k1 + 1):ncol(Y)], 
                ncol = m)
            AICbench1 <- VARXForecastEval(matrix(ZFull$Y[, 1:k1], 
                ncol = k1), as.matrix(X), p, s, T2, T, "AIC", 
                h = h)
            AICbench <- list()
            AICbench$Mean <- mean(AICbench1$MSFE)
            AICbench$SD <- sd(AICbench1$MSFE)/sqrt(length(AICbench1$MSFE))
            AICbench$preds <- AICbench1$pred
            AICbench$pvec <- AICbench1$p
            AICbench$svec <- AICbench1$s
            BICbench1 <- VARXForecastEval(matrix(ZFull$Y[, 1:k1], 
                ncol = k1), X, p, s, T2, T, "BIC", h = h)
            BICbench <- list()
            BICbench$Mean <- mean(BICbench1$MSFE)
            BICbench$SD <- sd(BICbench1$MSFE)/sqrt(length(BICbench1$MSFE))
            BICbench$preds <- BICbench1$pred
            BICbench$pvec <- BICbench1$p
            BICbench$svec <- BICbench1$s
        }
    }
    if (!VARX) {
        contemp = FALSE
    }
    if (VARX & contemp) {
        VARXL <- list(k = k1, s = s, contemp = contemp)
    }
    else if (VARX & !contemp) {
        VARXL <- list(k = k1, s = s, contemp = FALSE)
    }
    else {
        VARXL <- list()
    }
    results <- new("BigVAR.results", InSampMSFE = colMeans(MSFE), 
        InSampSD = apply(MSFE, 2, sd)/sqrt(nrow(MSFE)), LambdaGrid = gamm, 
        index = optind, OptimalLambda = gamopt, OOSMSFE = MSFEOOSAgg, 
        seoosmsfe = seoos, MeanMSFE = meanbench$Mean, AICMSFE = AICbench$Mean, 
        AICpvec = AICbench$pvec, AICsvec = AICbench$svec, AICPreds = AICbench$preds, 
        BICpvec = BICbench$pvec, BICsvec = BICbench$svec, BICPreds = BICbench$preds, 
        RWMSFE = RWbench$Mean, RWPreds = RWbench$preds, MeanSD = meanbench$SD, 
        MeanPreds = meanbench$preds, AICSD = AICbench$SD, BICMSFE = BICbench$Mean, 
        BICSD = BICbench$SD, RWSD = RWbench$SD, Data = object@Data, 
        lagmax = object@lagmax, Structure = object@Structure, 
        Minnesota = object@Minnesota, Relaxed = object@Relaxed, 
        Granularity = object@Granularity, horizon = object@horizon, 
        betaPred = betaPred, Zvals = Zvals, resids = resids, 
        VARXI = VARX, VARX = VARXL, preds = preds, T1 = T1, T2 = T2, 
        dual = dual, alpha = alphaopt, crossval = object@crossval, 
        ownlambdas = object@ownlambdas, tf = object@tf, recursive = recursive, 
        constvec = C, intercept = intercept, tol = tol, fitted = fitted, 
        lagmatrix = lagmatrix, betaArray = betaArray, window.size = object@window.size)
    return(results)
}
<bytecode: 0x555ac46e1f78>
<environment: namespace:BigVAR>

Signatures:
        object  
target  "BigVAR"
defined "BigVAR"
 --- function search by body ---
S4 Method cv.BigVAR:BigVAR defined in namespace BigVAR with signature BigVAR has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1