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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: network
> ### Title: Define a Network Generator
> ### Aliases: network
> 
> ### ** Examples
> 
> #--------------------------------------------------------------------------------------------------
> # EXAMPLE 1. USING igraph R PACKAGE TO SIMULATE NETWORKS
> #--------------------------------------------------------------------------------------------------
> 
> #--------------------------------------------------------------------------------------------------
> # Example of a network sampler, will be provided as "netfun" argument to network(, netfun=);
> # Generates a random graph according to the G(n,m) Erdos-Renyi model using the igraph package;
> # Returns (n,Kmax) matrix of net IDs (friends) by row;
> # Row i contains the IDs (row numbers) of i's friends;
> # i's friends are assumed connected to i and can influence i in equations defined by node())
> # When i has less than Kmax friends, the remaining i row entries are filled with NAs;
> # Argument m_pn: > 0
> # a total number of edges in the network as a fraction (or multiplier) of n (sample size)
> #--------------------------------------------------------------------------------------------------
> gen.ER <- function(n, m_pn, ...) {
+   m <- as.integer(m_pn*n)
+   if (n<=10) m <- 20
+   igraph.ER <- igraph::sample_gnm(n = n, m = m, directed = TRUE)
+   sparse_AdjMat <- igraph.to.sparseAdjMat(igraph.ER)
+   NetInd_out <- sparseAdjMat.to.NetInd(sparse_AdjMat)
+   return(NetInd_out$NetInd_k)
+ }
> 
> D <- DAG.empty()
> # Sample ER model network using igraph::sample_gnm with m_pn argument:
> D <- D + network("ER.net", netfun = "gen.ER", m_pn = 50)
> # W1 - categorical (6 categories, 1-6):
> D <- D +
+   node("W1", distr = "rcat.b1",
+         probs = c(0.0494, 0.1823, 0.2806, 0.2680, 0.1651, 0.0546)) +
+ # W2 - binary infection status, positively correlated with W1:
+   node("W2", distr = "rbern", prob = plogis(-0.2 + W1/3)) +
+ # W3 - binary confounder:
+   node("W3", distr = "rbern", prob = 0.6)
> # A[i] is a function W1[i] and the total of i's friends values W1, W2 and W3:
> D <- D + node("A", distr = "rbern",
+               prob = plogis(2 + -0.5 * W1 +
+                             -0.1 * sum(W1[[1:Kmax]]) +
+                             -0.4 * sum(W2[[1:Kmax]]) +
+                             -0.7 * sum(W3[[1:Kmax]])),
+               replaceNAw0 = TRUE)
> # Y[i] is a function of netW3 (friends of i W3 values) and the total N of i's friends
> # who are infected AND untreated:
> D <- D + node("Y", distr = "rbern",
+               prob = plogis(-1 + 2 * sum(W2[[1:Kmax]] * (1 - A[[1:Kmax]])) +
+                             -2 * sum(W3[[1:Kmax]])
+                             ),
+               replaceNAw0 = TRUE)
> # Can add N untreated friends to the above outcome Y equation: sum(1 - A[[1:Kmax]]):
> D <- D + node("Y", distr = "rbern",
+               prob = plogis(-1 + 1.5 * sum(W2[[1:Kmax]] * (1 - A[[1:Kmax]])) +
+                             -2 * sum(W3[[1:Kmax]]) +
+                             0.25 * sum(1 - A[[1:Kmax]])
+                             ),
+               replaceNAw0 = TRUE)
existing node Y was modified
> # Can add N infected friends at baseline to the above outcome Y equation: sum(W2[[1:Kmax]]):
> D <- D + node("Y", distr = "rbern",
+               prob = plogis(-1 + 1 * sum(W2[[1:Kmax]] * (1 - A[[1:Kmax]])) +
+                             -2 * sum(W3[[1:Kmax]]) +
+                             0.25 * sum(1 - A[[1:Kmax]]) +
+                             0.25 * sum(W2[[1:Kmax]])
+                             ),
+               replaceNAw0 = TRUE)
existing node Y was modified
> Dset <- set.DAG(D, n.test = 100)
...automatically assigning order attribute to some nodes...
node ER.net, order:1
node W1, order:2
node W2, order:3
node W3, order:4
node A, order:5
node Y, order:6
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
simcausal
 --- call from context --- 
standardize_param(newNodeParams$dist_params[[idx]])
 --- call from argument --- 
if (class(distparam) %in% "list") {
    distparam <- lapply(distparam, check_len)
    distparam <- do.call("cbind", distparam)
} else if (is.vector(distparam)) {
    distparam <- check_len(distparam)
} else if (is.matrix(distparam)) {
    if (nrow(distparam) == 1) {
    }
    else if (nrow(distparam) == Nsamp) {
        distparam <- distparam[!EFUP.prev, , drop = FALSE]
    }
    else {
        if (verbose) 
            message("evaluating node " %+% cur.node$name %+% 
                " expression(s): One of the distribution parameters evaluated to a matrix of non-standard dimensions (its neither 1 nor n rows), make sure the distribution function knows how to handle it.")
    }
} else {
    if (verbose) 
        message("The node " %+% cur.node$name %+% " expression(s): " %+% 
            expr_str %+% ".\n One of the formulas evaluated to unknown data type. Make sure the distribution function knowns how to handle it...")
}
 --- R stacktrace ---
where 1: standardize_param(newNodeParams$dist_params[[idx]])
where 2: sampleNodeDistr(newNodeParams = newNodeParams, distr = distr, 
    EFUP.prev = EFUP.prev, cur.node = cur.node, expr_str = cur.node$dist_params)
where 3: simFromDAG(DAG = DAG, Nsamp = n, wide = wide, LTCF = LTCF, rndseed = rndseed, 
    rndseed.reset.node = rndseed.reset.node, verbose = verbose)
where 4: simobs(inputDAG, n = n.test, rndseed = rndseed)
where 5: doTryCatch(return(expr), name, parentenv, handler)
where 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
where 7: tryCatchList(expr, classes, parentenv, handlers)
where 8: tryCatch(expr, error = function(e) {
    call <- conditionCall(e)
    if (!is.null(call)) {
        if (identical(call[[1L]], quote(doTryCatch))) 
            call <- sys.call(-4L)
        dcall <- deparse(call)[1L]
        prefix <- paste("Error in", dcall, ": ")
        LONG <- 75L
        sm <- strsplit(conditionMessage(e), "\n")[[1L]]
        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")
        if (is.na(w)) 
            w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], 
                type = "b")
        if (w > LONG) 
            prefix <- paste0(prefix, "\n  ")
    }
    else prefix <- "Error : "
    msg <- paste0(prefix, conditionMessage(e), "\n")
    .Internal(seterrmessage(msg[1L]))
    if (!silent && isTRUE(getOption("show.error.messages"))) {
        cat(msg, file = outFile)
        .Internal(printDeferredWarnings())
    }
    invisible(structure(msg, class = "try-error", condition = e))
})
where 9: try(simobs(inputDAG, n = n.test, rndseed = rndseed))
where 10: set.DAG(D, n.test = 100)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (distparam) 
{
    check_len <- function(param) {
        len <- length(param)
        if (len == 1) {
            param <- rep.int(param, N_notNA_samp)
        }
        else if (len == Nsamp) {
            param <- param[!EFUP.prev]
        }
        else {
            if (verbose) 
                message("evaluating node " %+% cur.node$name %+% 
                  " expression(s): " %+% expr_str %+% ".\n One of the distribution parameters evaluated to non-standard vector length (its neither 1 nor n), make sure the distribution function knows how to handle it.")
        }
        param
    }
    if (class(distparam) %in% "list") {
        distparam <- lapply(distparam, check_len)
        distparam <- do.call("cbind", distparam)
    }
    else if (is.vector(distparam)) {
        distparam <- check_len(distparam)
    }
    else if (is.matrix(distparam)) {
        if (nrow(distparam) == 1) {
        }
        else if (nrow(distparam) == Nsamp) {
            distparam <- distparam[!EFUP.prev, , drop = FALSE]
        }
        else {
            if (verbose) 
                message("evaluating node " %+% cur.node$name %+% 
                  " expression(s): One of the distribution parameters evaluated to a matrix of non-standard dimensions (its neither 1 nor n rows), make sure the distribution function knows how to handle it.")
        }
    }
    else {
        if (verbose) 
            message("The node " %+% cur.node$name %+% " expression(s): " %+% 
                expr_str %+% ".\n One of the formulas evaluated to unknown data type. Make sure the distribution function knowns how to handle it...")
    }
    distparam
}
<bytecode: 0x55c5093cbc88>
<environment: 0x55c511dc3d18>
 --- function search by body ---
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(distparam) %in% "list") { : 
  the condition has length > 1
Error in set.DAG(D, n.test = 100) : 
...attempt to simulate data from DAG failed...
Execution halted