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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: SJ
> ### Title: Estimate a graph with Spacejam
> ### Aliases: SJ SJ.dag
> ### Keywords: graphs optimize
> 
> ### ** Examples
> 
> #########Create graph and distribution used in Figure 2 of Voorman, Shojaie and Witten (2013):
> p <- 100 #variables
> n <- 50 #observations
> 
> #Generate Graph
> set.seed(20)
> g <- rdag(p,80)
> mylayout <- layout.fruchterman.reingold(g)
> 
> par(mfrow=c(1,2))
> plot(g, layout = mylayout, edge.color = "gray50", 
+         vertex.color = "red", vertex.size = 3, vertex.label = NA, 
+         edge.arrow.size = 0.4)
> plot(moralize(g), layout = mylayout, edge.color = "gray50", 
+         vertex.color = "red", vertex.size = 3, vertex.label = NA, 
+         edge.arrow.size = 0.4)
> 
> #create a distribution on the DAG using cubic polynomials with random normal coefficients 
> #with standard deviations of 1, 0.5 and 0.5, (i.e. giving more weight to linear association than quadratic or cubic)
> data <- generate.dag.data(g,n,basesd=c(1,0.5,0.5))
> X <- data$X
> 
> #Fit conditional independence graph at one lambda , using the default basis functions (cubic polynomials).
> fit1 <- SJ(X, lambda = 0.6)
> 
> #Fit conditional independence graph at 10 (hopefully reasonable) lambdas:
> fit2 <- SJ(X, length = 10)
> 
> #Fit conditional independence graph using quadratic basis functions:
> fit3 <- SJ(X, bfun = function(x){cbind(x,x^2)}, length = 10)
> 
> #Fit the DAG using default causal ordering 1:p, and at 10 lambdas
> fit4 <- SJ.dag(X, length = 10)
> fit4
Object of class "SJ.dag"
Contains the graphs:
   lambda Edges      bic
1   0.800     0 19459.10
2   0.740     9 19477.89
3   0.670    24 19493.19
4   0.600    43 19481.95
5   0.530    61 19432.97
6   0.450   109 19426.46
7   0.360   231 19648.50
8   0.270   542 20645.94
9   0.160  1134 23135.28
10  0.046  2358 27793.09
Call:
	SJ.dag(X = X, length = 10)
> 
> #plot the DAGs, and the true graph
> par(mfrow=c(1,3))
> plot(g, layout=mylayout, edge.color = "gray50", vertex.color = "red", vertex.size = 3, vertex.label = NA, edge.arrow.size = 0.4, main="True DAG")
> plot(fit4, layout = mylayout, which= 4, main= paste0("lambda = ",round(fit4$lambda[4],2) ))
> plot(fit4, layout = mylayout, main = "min BIC")
> 
> ###For additional replications using the same DAG distribution use e.g.
> data <- generate.dag.data(g,n,funclist = data$funclist)
> 
> 
> #### Screen out edges whose corresponding nodes have low spearman correlation:
> # useful for approximating spacejam in high dimesnions
> S <- cor(data$X, method = "spearman")
> G.max <- S > 0.1
> mean(G.max) #~75% of edges removed
[1] 0.2458
> 
> system.time({fit.screen <- SJ(X, G.max = G.max,length=20)})
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
spacejam
 --- call from context --- 
SJ(X, G.max = G.max, length = 20)
 --- call from argument --- 
if (class(G.max) == "igraph") G.max <- get.adjacency(G.max, sparse = TRUE) == 
    1
 --- R stacktrace ---
where 1: SJ(X, G.max = G.max, length = 20)
where 2: system.time({
    fit.screen <- SJ(X, G.max = G.max, length = 20)
})

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (X, bfun = bs, lambda = NULL, length = NULL, verbose = FALSE, 
    b0 = NULL, maxit = 100, tol = .Machine$double.eps^0.25, G.max = NULL) 
{
    cl <- match.call()
    bfun <- match.fun(bfun)
    n <- nrow(X)
    p <- ncol(X)
    k <- ncol(bfun(X[, 1]))
    if (!is.null(b0) & any(dim(b0) != c(n, p * k))) {
        stop("dimensions of b0 not compatible with basis function")
    }
    if (!is.null(G.max)) {
        if (class(G.max) == "igraph") 
            G.max <- get.adjacency(G.max, sparse = TRUE) == 1
        stopifnot(storage.mode(G.max) == "logical")
        stopifnot(ncol(X) == ncol(G.max))
    }
    if (!is.null(lambda) & !is.null(length)) {
        if (length(lambda) != length) 
            warning("Lambda and length not compatible. Using lambda")
    }
    if (is.null(lambda) & is.null(length)) 
        length = 10
    if (!is.null(lambda) & any(lambda < 0)) 
        stop("lambda must be positive")
    X <- apply(X, 2, scale)
    bigX <- matrix(NA, nrow = k * p, ncol = n)
    for (j in 1:p) {
        bigX[p * (1:k - 1) + j, ] <- t(svd(apply(bfun(X[, j]), 
            2, scale, scale = F))$u * sqrt(n - 1))
    }
    if (is.null(lambda)) {
        M <- matrix(NA, nrow = p, ncol = p)
        tmp <- bigX %*% X/(n - 1)
        for (i in 1:p) {
            for (j in (1:p)[-i]) {
                M[i, j] <- sum(tmp[p * (1:k - 1) + j, i]^2)
            }
        }
        M <- sqrt(M + t(M))
        lmin <- sort(c(M))[p]
        lmax <- max(M, na.rm = T)
        lambda <- rev(log(seq(exp(lmin), exp(lmax), length = length)))
    }
    if (verbose) 
        cat("Progress: \n")
    dfs <- rss <- matrix(0, p, length(lambda))
    adjmat <- array(dim = c(p, p, length(lambda)))
    for (i in 1:length(lambda)) {
        out <- grpsel(X = X, bigX = bigX, lambda = lambda[i], 
            n = n, k = k, p = p, tol = tol, maxit = maxit, b0 = b0, 
            G.max = G.max)
        b0 = out$b0
        adjmat[, , i] <- out$G
        tmp <- rowsum(t(out$betas^2) * (n - 1), rep(1:p, k))
        dfs[, i] <- colSums(out$G) + (k - 1) * rowSums((tmp)/(tmp + 
            lambda[i]))
        rss[, i] <- colSums((X - t(out$betas %*% bigX))^2)
        if (verbose) 
            cat(".")
    }
    class(out) <- "SJ"
    out$X = X
    out$graph <- apply(adjmat, 3, function(GG) {
        graph.adjacency(GG, mode = "undirected")
    })
    out$cl <- cl
    out$bigX = bigX
    out$n = n
    out$k = k
    out$p = p
    out$tol = tol
    out$maxit = maxit
    out$verbose = verbose
    out$G.max = G.max
    out$lambda = lambda
    out$G = adjmat
    out$dfs = dfs
    out$rss = rss
    out$ecount <- unlist(lapply(out$graph, ecount))
    out$bic = colSums(n * log(rss) + dfs * log(n))
    return(out)
}
<bytecode: 0x55d1499aa5b0>
<environment: namespace:spacejam>
 --- function search by body ---
Function SJ in namespace spacejam has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(G.max) == "igraph") G.max <- get.adjacency(G.max, sparse = TRUE) ==  : 
  the condition has length > 1
Calls: system.time -> SJ
Timing stopped at: 1.023 0.059 1.921
Execution halted