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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: Data2fd
> ### Title: Create a functional data object from data
> ### Aliases: Data2fd
> ### Keywords: smooth
> 
> ### ** Examples
> 
> ##
> ## Simplest possible example:  constant function
> ##
> # 1 basis, order 1 = degree 0 = constant function
> b1.1 <- create.bspline.basis(nbasis=1, norder=1)
> # data values: 1 and 2, with a mean of 1.5
> y12 <- 1:2
> # smooth data, giving a constant function with value 1.5
> fd1.1 <- Data2fd(y12, basisobj=b1.1)
'y' is missing, using 'argvals'
'argvals' is missing;  using seq( 0 ,  1 , length= 2 )
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
fda
 --- call from context --- 
smooth.basis1(argvals, y, fdParobj, wtvec = wtvec, fdnames = fdnames, 
    covariates = covariates, method = method, dfscale = dfscale, 
    returnMatrix = returnMatrix)
 --- call from argument --- 
if (class(Lmat) == "try-error") {
    Beig <- eigen(Bmat, symmetric = TRUE)
    BgoodEig <- (Beig$values > 0)
    Brank <- sum(BgoodEig)
    if (Brank < dim(Bmat)[1]) 
        warning("Matrix of basis function values has rank ", 
            Brank, " < dim(fdobj$basis)[2] = ", length(BgoodEig), 
            "  ignoring null space")
    goodVec <- Beig$vectors[, BgoodEig]
    Bmatinv <- (goodVec %*% (Beig$values[BgoodEig] * t(goodVec)))
} else {
    Lmatinv <- solve(Lmat)
    Bmatinv <- Lmatinv %*% t(Lmatinv)
}
 --- R stacktrace ---
where 1: smooth.basis1(argvals, y, fdParobj, wtvec = wtvec, fdnames = fdnames, 
    covariates = covariates, method = method, dfscale = dfscale, 
    returnMatrix = returnMatrix)
where 2: smooth.basis(argvals, y, fdP, wtvec = wtvec, fdnames = fdnames, 
    covariates = covariates, method = "chol", dfscale = dfscale)
where 3: smooth.basisPar(argvals = argvals, y = y, fdobj = basisobj, Lfdobj = nderiv, 
    lambda = lambda, fdnames = fdnames, covariates = covariates, 
    method = "chol", dfscale = dfscale)
where 4: eval(substitute(expr), data, enclos = parent.frame())
where 5: eval(substitute(expr), data, enclos = parent.frame())
where 6: with.default(argChk, smooth.basisPar(argvals = argvals, y = y, 
    fdobj = basisobj, Lfdobj = nderiv, lambda = lambda, fdnames = fdnames, 
    covariates = covariates, method = "chol", dfscale = dfscale))
where 7: with(argChk, smooth.basisPar(argvals = argvals, y = y, fdobj = basisobj, 
    Lfdobj = nderiv, lambda = lambda, fdnames = fdnames, covariates = covariates, 
    method = "chol", dfscale = dfscale))
where 8: Data2fd(y12, basisobj = b1.1)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (argvals = 1:n, y, fdParobj, wtvec = NULL, fdnames = NULL, 
    covariates = NULL, method = "chol", dfscale = 1, returnMatrix = FALSE) 
{
    if (is.vector(y)) 
        y <- matrix(y, length(y), 1)
    dimy <- dim(y)
    n <- dimy[1]
    ycheck <- ycheck(y, n)
    y <- ycheck$y
    y0 <- y
    nrep <- ycheck$ncurve
    nvar <- ycheck$nvar
    ndim <- ycheck$ndim
    ydim <- dim(y)
    if (!is.numeric(argvals)) 
        stop("'argvals' is not numeric.")
    argvals <- as.vector(argvals)
    fdParobj <- fdParcheck(fdParobj)
    fdobj <- fdParobj$fd
    lambda <- fdParobj$lambda
    Lfdobj <- fdParobj$Lfd
    penmat <- fdParobj$penmat
    if (lambda < 0) {
        warning("Value of 'lambda' was negative  0 used instead.")
        lambda <- 0
    }
    wtlist <- wtcheck(n, wtvec)
    wtvec <- wtlist$wtvec
    onewt <- wtlist$onewt
    matwt <- wtlist$matwt
    tnames <- dimnames(y)[[1]]
    if (is.null(tnames)) 
        tnames <- 1:n
    nderiv <- Lfdobj$nderiv
    basisobj <- fdobj$basis
    dropind <- basisobj$dropind
    ndropind <- length(dropind)
    nbasis <- basisobj$nbasis - ndropind
    names <- basisobj$names
    if (ndropind > 0) {
        names <- names[-dropind]
    }
    if (ndim == 2) {
        coef <- matrix(0, nbasis, nrep)
        ynames <- dimnames(y)[[2]]
        vnames <- "value"
        dimnames(coef) <- list(names, ynames)
    }
    if (ndim == 3) {
        coef <- array(0, c(nbasis, nrep, nvar))
        ynames <- dimnames(y)[[2]]
        vnames <- dimnames(y)[[3]]
        dimnames(coef) <- list(names, ynames, vnames)
    }
    if (!is.null(covariates)) {
        if (!is.numeric(covariates)) {
            stop(paste("smooth_basis_LS:covariates", "Optional argument COVARIATES is not numeric."))
        }
        if (dim(covariates)[1] != n) {
            stop(paste("smooth_basis_LS:covariates", "Optional argument COVARIATES has incorrect number of rows."))
        }
        q <- dim(covariates)[2]
    }
    else {
        q <- 0
        beta. <- NULL
    }
    tnames <- dimnames(y)[[1]]
    if (is.null(tnames)) 
        tnames <- 1:n
    basismat <- eval.basis(as.vector(argvals), basisobj, 0, returnMatrix)
    if (method == "chol") {
        if (n > nbasis + q || lambda > 0) {
            if (!is.null(covariates)) {
                ind1 <- 1:n
                ind2 <- (nbasis + 1):(nbasis + q)
                basismat <- as.matrix(basismat)
                basismat <- cbind(basismat, matrix(0, dim(basismat)[1], 
                  q))
                basismat[ind1, ind2] <- covariates
            }
            if (matwt) {
                wtfac <- chol(wtvec)
                basisw <- wtvec %*% basismat
            }
            else {
                rtwtvec <- sqrt(wtvec)
                rtwtmat <- matrix(rtwtvec, n, nrep)
                basisw <- (wtvec %*% matrix(1, 1, nbasis + q)) * 
                  basismat
            }
            Bmat <- t(basisw) %*% basismat
            Bmat0 <- Bmat
            if (ndim < 3) {
                Dmat <- t(basisw) %*% y
            }
            else {
                Dmat <- array(0, c(nbasis + q, nrep, nvar))
                for (ivar in 1:nvar) {
                  Dmat[, , ivar] <- crossprod(basisw, y[, , ivar])
                }
            }
            if (lambda > 0) {
                if (is.null(penmat)) 
                  penmat <- eval.penalty(basisobj, Lfdobj)
                Bnorm <- sqrt(sum(diag(t(Bmat0) %*% Bmat0)))
                pennorm <- sqrt(sum(penmat * penmat))
                condno <- pennorm/Bnorm
                if (lambda * condno > 1e+12) {
                  lambda <- 1e+12/condno
                  warning(paste("lambda reduced to", lambda, 
                    "to prevent overflow"))
                }
                if (!is.null(covariates)) {
                  penmat <- rbind(cbind(penmat, matrix(0, nbasis, 
                    q)), cbind(matrix(0, q, nbasis), matrix(0, 
                    q, q)))
                }
                Bmat <- Bmat0 + lambda * penmat
            }
            else {
                penmat <- NULL
                Bmat <- Bmat0
            }
            Bmat <- (Bmat + t(Bmat))/2
            Lmat <- try(chol(Bmat), silent = TRUE)
            if (class(Lmat) == "try-error") {
                Beig <- eigen(Bmat, symmetric = TRUE)
                BgoodEig <- (Beig$values > 0)
                Brank <- sum(BgoodEig)
                if (Brank < dim(Bmat)[1]) 
                  warning("Matrix of basis function values has rank ", 
                    Brank, " < dim(fdobj$basis)[2] = ", length(BgoodEig), 
                    "  ignoring null space")
                goodVec <- Beig$vectors[, BgoodEig]
                Bmatinv <- (goodVec %*% (Beig$values[BgoodEig] * 
                  t(goodVec)))
            }
            else {
                Lmatinv <- solve(Lmat)
                Bmatinv <- Lmatinv %*% t(Lmatinv)
            }
            if (ndim < 3) {
                coef <- Bmatinv %*% Dmat
                if (!is.null(covariates)) {
                  beta. <- as.matrix(coef[(nbasis + 1):(nbasis + 
                    q), ])
                  coef <- as.matrix(coef[1:nbasis, ])
                }
                else {
                  beta. <- NULL
                }
            }
            else {
                coef <- array(0, c(nbasis, nrep, nvar))
                if (!is.null(covariates)) {
                  beta. <- array(0, c(q, nrep, nvar))
                }
                else {
                  beta. <- NULL
                }
                for (ivar in 1:nvar) {
                  coefi <- Bmatinv %*% Dmat[, , ivar]
                  if (!is.null(covariates)) {
                    beta.[, , ivar] <- coefi[(nbasis + 1):(nbasis + 
                      q), ]
                    coef[, , ivar] <- coefi[1:nbasis, ]
                  }
                  else {
                    coef[, , ivar] <- coefi
                  }
                }
            }
        }
        else {
            if (n == nbasis + q) {
                if (ndim == 2) {
                  coef <- solve(basismat, y)
                }
                else {
                  for (ivar in 1:var) coef[1:n, , ivar] <- solve(basismat, 
                    y[, , ivar])
                }
                penmat <- NULL
            }
            else {
                stop("The number of basis functions = ", nbasis + 
                  q, " exceeds ", n, " = the number of points to be smoothed.")
            }
        }
    }
    else {
        if (n > nbasis || lambda > 0) {
            if (!onewt) {
                if (matwt) {
                  wtfac <- chol(wtvec)
                  basismat.aug <- wtfac %*% basismat
                  if (ndim < 3) {
                    y <- wtfac %*% y
                  }
                  else {
                    for (ivar in 1:nvar) {
                      y[, , ivar] <- wtfac %*% y[, , ivar]
                    }
                  }
                }
                else {
                  rtwtvec <- sqrt(wtvec)
                  basismat.aug <- matrix(rtwtvec, n, nbasis) * 
                    basismat
                  if (ndim < 3) {
                    y <- matrix(rtwtvec, n, nrep) * y
                  }
                  else {
                    for (ivar in 1:nvar) {
                      y[, , ivar] <- matrix(rtwtvec, n, nrep) * 
                        y[, , ivar]
                    }
                  }
                }
            }
            else {
                basismat.aug <- basismat
            }
            if (lambda > 0) {
                if (is.null(penmat)) 
                  penmat <- eval.penalty(basisobj, Lfdobj)
                eiglist <- eigen(penmat)
                Dvec <- eiglist$values
                Vmat <- eiglist$vectors
                neiglow <- nbasis - nderiv
                naug <- n + neiglow
                if (Dvec[neiglow] <= 0) {
                  stop(paste("smooth_basis:eig", "Eigenvalue(NBASIS-NDERIV) of penalty matrix ", 
                    "is not positive check penalty matrix."))
                }
                indeig <- 1:neiglow
                penfac <- Vmat[, indeig] %*% diag(sqrt(Dvec[indeig]))
                basismat.aug <- rbind(basismat.aug, sqrt(lambda) * 
                  t(penfac))
                if (ndim < 3) {
                  y <- rbind(y, matrix(0, nbasis - nderiv, nrep))
                }
                else {
                  y <- array(0, c(ydim[1] + nbasis - nderiv, 
                    ydim[2], ydim[3]))
                  y[1:ydim[1], , ] <- y0
                  ind1 <- (1:(nbasis - nderiv)) + ydim[1]
                  for (ivar in 1:nvar) {
                    y[ind1, , ivar] <- matrix(0, nbasis - nderiv, 
                      nrep)
                  }
                }
            }
            else {
                penmat <- NULL
            }
            if (!is.null(covariates)) {
                ind1 <- 1:n
                ind2 <- (nbasis + 1):(nbasis + q)
                basismat.aug <- cbind(basismat.aug, matrix(0, 
                  naug, q))
                if (!onewt) {
                  if (matwt) {
                    basismat.aug[ind1, ind2] <- wtfac %*% covariates
                  }
                  else {
                    wtfac <- matrix(rtwtvec, n, q)
                    basismat.aug[ind1, ind2] <- wtfac * covariates
                  }
                }
                else {
                  basismat.aug[ind1, ind2] <- covariates
                }
                penmat <- rbind(cbind(penmat, matrix(0, nbasis, 
                  q)), cbind(matrix(0, q, nbasis), matrix(0, 
                  q, q)))
            }
            qr <- qr(basismat.aug)
            if (ndim < 3) {
                coef <- qr.coef(qr, y)
                if (!is.null(covariates)) {
                  beta. <- coef[ind2, ]
                  coef <- coef[1:nbasis, ]
                }
                else {
                  beta. <- NULL
                }
            }
            else {
                coef <- array(0, c(nbasis, nrep, nvar))
                if (!is.null(covariates)) {
                  beta. <- array(0, c(q, nrep, nvar))
                }
                else {
                  beta. <- NULL
                }
                for (ivar in 1:nvar) {
                  coefi <- qr.coef(qr, y[, , ivar])
                  if (!is.null(covariates)) {
                    beta.[, , ivar] <- coefi[ind2, ]
                    coef[, , ivar] <- coefi[1:nbasis, ]
                  }
                  else {
                    coef[, , ivar] <- coefi
                  }
                }
            }
        }
        else {
            if (n == nbasis + q) {
                if (ndim == 2) {
                  coef <- solve(basismat, y)
                }
                else {
                  for (ivar in 1:var) coef[, , ivar] <- solve(basismat, 
                    y[, , ivar])
                }
                penmat <- NULL
            }
            else {
                stop(paste("The number of basis functions = ", 
                  nbasis, " exceeds ", n, " = the number of points to be smoothed.  "))
            }
        }
    }
    if (onewt) {
        temp <- t(basismat) %*% basismat
        if (lambda > 0) {
            temp <- temp + lambda * penmat
        }
        L <- chol(temp)
        MapFac <- solve(t(L), t(basismat))
        y2cMap <- solve(L, MapFac)
    }
    else {
        if (matwt) {
            temp <- t(basismat) %*% wtvec %*% basismat
        }
        else {
            temp <- t(basismat) %*% (as.vector(wtvec) * basismat)
        }
        if (lambda > 0) {
            temp <- temp + lambda * penmat
        }
        L <- chol((temp + t(temp))/2)
        MapFac <- solve(t(L), t(basismat))
        if (matwt) {
            y2cMap <- solve(L, MapFac %*% wtvec)
        }
        else {
            y2cMap <- solve(L, MapFac * rep(as.vector(wtvec), 
                e = nrow(MapFac)))
        }
    }
    df. <- sum(diag(y2cMap %*% basismat))
    if (ndim < 3) {
        yhat <- basismat[, 1:nbasis] %*% coef
        SSE <- sum((y[1:n, ] - yhat)^2)
        if (is.null(ynames)) 
            ynames <- dimnames(yhat)[[2]]
    }
    else {
        SSE <- 0
        yhat <- array(0, c(n, nrep, nvar))
        dimnames(yhat) <- list(dimnames(basismat)[[1]], dimnames(coef)[[2]], 
            dimnames(coef)[[3]])
        for (ivar in 1:nvar) {
            yhat[, , ivar] <- basismat[, 1:nbasis] %*% coef[, 
                , ivar]
            SSE <- SSE + sum((y[1:n, , ivar] - yhat[, , ivar])^2)
        }
        if (is.null(ynames)) 
            ynames <- dimnames(yhat)[[2]]
        if (is.null(vnames)) 
            vnames <- dimnames(yhat)[[2]]
    }
    if (is.null(ynames)) 
        ynames <- paste("rep", 1:nrep, sep = "")
    if (is.null(vnames)) 
        vnames <- paste("value", 1:nvar, sep = "")
    if (!is.null(df.) && df. < n) {
        if (ndim < 3) {
            gcv <- rep(0, nrep)
            for (i in 1:nrep) {
                SSEi <- sum((y[1:n, i] - yhat[, i])^2)
                gcv[i] <- (SSEi/n)/((n - df.)/n)^2
            }
            if (ndim > 1) 
                names(gcv) <- ynames
        }
        else {
            gcv <- matrix(0, nrep, nvar)
            for (ivar in 1:nvar) {
                for (i in 1:nrep) {
                  SSEi <- sum((y[1:n, i, ivar] - yhat[, i, ivar])^2)
                  gcv[i, ivar] <- (SSEi/n)/((n - df.)/n)^2
                }
            }
            dimnames(gcv) <- list(ynames, vnames)
        }
    }
    else {
        gcv <- NULL
    }
    if (is.null(fdnames)) {
        fdnames <- list(time = tnames, reps = ynames, values = vnames)
    }
    if (ndim < 3) {
        coef <- as.matrix(coef)
        fdobj <- fd(coef[1:nbasis, ], basisobj, fdnames)
    }
    else {
        fdobj <- fd(coef[1:nbasis, , ], basisobj, fdnames)
    }
    if (!is.null(penmat) && !is.null(covariates)) 
        penmat <- penmat[1:nbasis, 1:nbasis]
    smoothlist <- list(fd = fdobj, df = df., gcv = gcv, beta = beta., 
        SSE = SSE, penmat = penmat, y2cMap = y2cMap, argvals = argvals, 
        y = y0)
    class(smoothlist) <- "fdSmooth"
    return(smoothlist)
}
<bytecode: 0x564e0f62d020>
<environment: namespace:fda>
 --- function search by body ---
Function smooth.basis1 in namespace fda has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(Lmat) == "try-error") { : the condition has length > 1
Calls: Data2fd ... eval -> smooth.basisPar -> smooth.basis -> smooth.basis1
Execution halted