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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: dgp_spsur
> ### Title: Generation of a random dataset with a spatial SUR structure.
> ### Aliases: dgp_spsur
> 
> ### ** Examples
> 
> ####################################
> ######## CROSS SECTION DATA ########
> ####################################
> 
> ####################################
> #### Example 1: DGP SLM model
> ####################################
> rm(list = ls()) # Clean memory
> Tm <- 1 # Number of time periods
> G <- 3 # Number of equations
> N <- 50 # Number of spatial elements
> p <- 3 # Number of independent variables
> Sigma <- matrix(0.3, ncol = G, nrow = G)
> diag(Sigma) <- 1
> Betas <- c(1,2,3,1,-1,0.5,1,-0.5,2)
> lambda <- 0.5 # level of spatial dependence
> rho <- 0.0 # spatial autocorrelation error term = 0
> #  random coordinates
> co <- cbind(runif(N,0,1),runif(N,0,1))
> W <- spdep::nb2mat(spdep::knn2nb(spdep::knearneigh(co, k = 5,
+                                                    longlat = FALSE)))
> DGP <- dgp_spsur(Sigma = Sigma, Betas = Betas,
+                  rho = rho, lambda = lambda, Tm = Tm,
+                  G = G, N = N, p = p, W = W)
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
spsur
 --- call from context --- 
dgp_spsur(Sigma = Sigma, Betas = Betas, rho = rho, lambda = lambda, 
    Tm = Tm, G = G, N = N, p = p, W = W)
 --- call from argument --- 
if (class(W) != "matrix") W <- as.matrix(W)
 --- R stacktrace ---
where 1: dgp_spsur(Sigma = Sigma, Betas = Betas, rho = rho, lambda = lambda, 
    Tm = Tm, G = G, N = N, p = p, W = W)

 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context --- 
function (Sigma, Tm = 1, G, N, Betas, Thetas = NULL, rho = NULL, 
    lambda = NULL, p = NULL, W = NULL, X = NULL, pdfU = "nvrnorm", 
    pdfX = "nvrnorm") 
{
    if (!is.null(W)) {
        if (class(W) != "matrix") 
            W <- as.matrix(W)
        rsumW <- rowSums(W)
        rsumW[rsumW == 0] <- 1
        nW <- dim(W)[1]
        W <- W/matrix(rep(rsumW, each = nW), nrow = nW, ncol = nW, 
            byrow = TRUE)
        W <- Matrix::Matrix(W)
    }
    else W <- Matrix::Diagonal(N)
    if (Tm > 1 && G == 1) {
        G <- Tm
        Tm <- 1
    }
    if (!is.null(Thetas)) 
        durbin <- TRUE
    else durbin <- FALSE
    if (!is.null(p) & length(p) == 1) 
        p <- matrix(p, nrow = G, ncol = 1)
    if (is.null(lambda)) 
        lambda <- rep(0, G)
    if (is.null(rho)) 
        rho <- rep(0, G)
    if (length(lambda) == 1) 
        lambda <- as.numeric(matrix(lambda, nrow = G, ncol = 1))
    if (length(rho) == 1) 
        rho <- as.numeric(matrix(rho, nrow = G, ncol = 1))
    if (is.null(X)) {
        if (is.null(p)) 
            stop("Arguments X and p can not be NULL simultaneously")
        if (pdfX == "nvrunif") {
            X <- cbind(matrix(1, N, 1), matrix(runif(N * (p[1] - 
                1)), N, (p[1] - 1)))
            for (i in 1:(G - 1)) {
                X <- Matrix::bdiag(X, cbind(matrix(1, N, 1), 
                  matrix(runif(N * (p[i + 1] - 1)), N, (p[i + 
                    1] - 1))))
            }
            if (Tm > 1) {
                for (i in 1:(Tm - 1)) {
                  X2 <- cbind(matrix(1, N, 1), matrix(runif(N * 
                    (p[1] - 1)), N, (p[1] - 1)))
                  for (i in 1:(G - 1)) {
                    X2 <- Matrix::bdiag(X2, cbind(matrix(1, N, 
                      1), matrix(runif(N * (p[i + 1] - 1)), N, 
                      (p[i + 1] - 1))))
                  }
                  X <- rbind(X, X2)
                }
            }
        }
        else if (pdfX == "nvrnorm") {
            X <- cbind(matrix(1, N, 1), matrix(rnorm(N * (p[1] - 
                1), 0, 1), N, (p[1] - 1)))
            for (i in 1:(G - 1)) {
                X <- Matrix::bdiag(X, cbind(matrix(1, N, 1), 
                  matrix(rnorm(N * (p[i + 1] - 1), 0, 1), N, 
                    (p[i + 1] - 1))))
            }
            if (Tm > 1) {
                for (i in 1:(Tm - 1)) {
                  X2 <- cbind(matrix(1, N, 1), matrix(rnorm(N * 
                    (p[1] - 1), 0, 1), N, (p[1] - 1)))
                  for (i in 1:(G - 1)) {
                    X2 <- Matrix::bdiag(X2, cbind(matrix(1, N, 
                      1), matrix(rnorm(N * (p[i + 1] - 1), 0, 
                      1), N, (p[i + 1] - 1))))
                  }
                  X <- rbind(X, X2)
                }
            }
        }
        else stop("pdfX only can be nvrnorm or nvrunif")
        nam <- c(paste0("Intercep_", 1), paste(paste0("X", 1, 
            "_"), 1:(p[1] - 1), sep = ""))
        if (length(p > 1)) {
            for (i in 2:(length(p))) {
                nam <- c(nam, c(paste0("Intercep_", i), paste(paste0("X", 
                  i, "_"), 1:(p[i] - 1), sep = "")))
            }
        }
        dimnames(X)[[2]] <- nam
    }
    if (is.null(p)) {
        if ((ncol(X)%%G) != 0) 
            stop("Argument p need to be set")
        p <- rep(ncol(X)/G, G)
    }
    IT <- Matrix::Diagonal(Tm)
    IR <- Matrix::Diagonal(N)
    IG <- Matrix::Diagonal(G)
    IGR <- Matrix::Diagonal(G * N)
    if (durbin) {
        WX <- (IT %x% IG %x% W) %*% X
        dimnames(WX)[[2]] <- paste0("W_", colnames(X))
        Xdurbin <- NULL
        pdurbin <- p - 1
        for (i in 1:length(p)) {
            if (i == 1) {
                Xdurbin <- cbind(X[, 1:p[i]], WX[, 2:p[i]])
                Coeff <- c(Betas[1:p[1]], Thetas[1:pdurbin[1]])
            }
            else {
                Xdurbin <- cbind(Xdurbin, X[, (cumsum(p)[i - 
                  1] + 1):cumsum(p)[i]], WX[, (cumsum(p)[i - 
                  1] + 2):cumsum(p)[i]])
                Coeff <- c(Coeff, Betas[(cumsum(p)[i - 1] + 1):cumsum(p)[i]], 
                  Thetas[(cumsum(pdurbin)[i - 1] + 1):cumsum(pdurbin)[i]])
            }
        }
    }
    S <- Sigma
    OME <- (IT %x% S) %x% IR
    chol_OME <- Matrix::Cholesky(OME)
    M <- Matrix::Matrix(0, ncol = 1, nrow = Tm * G * N)
    U <- matrix(sparseMVN::rmvn.sparse(n = 1, mu = M, CH = chol_OME, 
        prec = FALSE), ncol = 1)
    U <- Matrix::Matrix(U)
    if (pdfU == "lognvrnorm") 
        U <- exp(U)
    if (pdfU != "lognvrnorm" && pdfU != "nvrnorm") 
        print(" Improper pdf. The errors will be drawn from a multivariate Normal ")
    IBU <- Matrix::solve(IT %x% (IGR - diag(rho) %x% W), U)
    if (durbin) {
        Y <- Matrix::solve(IT %x% (IGR - diag(lambda) %x% W), 
            (Xdurbin %*% Coeff + IBU))
    }
    else {
        Y <- Matrix::solve(IT %x% (IGR - diag(lambda) %x% W), 
            (X %*% Betas + IBU))
    }
    results <- list(X = as.matrix(X), Y = as.matrix(Y))
}
<bytecode: 0x56054c3b8e50>
<environment: namespace:spsur>
 --- function search by body ---
Function dgp_spsur in namespace spsur has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1