Errors in running code in vignettes:
when running code in 'vignette2018.Rnw'

> op.orig <- options(width = 79, useFancyQuotes = FALSE, 
+     prompt = "> ", continue = "  ")

> Sys.setenv(LANGUAGE = "en")

> if (.Platform$OS.type != "windows") Sys.setlocale("LC_MESSAGES", 
+     "C")

> PCversion <- packageDescription("pcalg")$Version

> library(pcalg)

> stopifnot(require(Rgraphviz))
Loading required package: Rgraphviz
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, basename, cbind, colnames, dirname, do.call,
    duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
    lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
    pmin.int, rank, rbind, rownames, sapply, setdiff, sort, table,
    tapply, union, unique, unsplit, which.max, which.min

Loading required package: grid

> library(graph)

> showF <- function(f, width = 50) {
+     nam <- deparse(substitute(f))
+     stopifnot(is.function(f))
+     ll <- capture.output(str(removeSource(f .... [TRUNCATED] 

> data("gmG", package = "pcalg")

> suffStat <- list(C = cor(gmG8$x), n = nrow(gmG8$x))

> varNames <- gmG8$g@nodes

> skel.gmG8 <- skeleton(suffStat, indepTest = gaussCItest, 
+     labels = varNames, alpha = 0.01)

> pc.gmG8 <- pc(suffStat, indepTest = gaussCItest, labels = varNames, 
+     alpha = 0.01)

> stopifnot(require(Rgraphviz))

> par(mfrow = c(1, 3))

> plot(gmG8$g, main = "")

> box(col = "gray")

> plot(skel.gmG8, main = "")

> box(col = "gray")

> plot(pc.gmG8, main = "")

> box(col = "gray")

> data("gmL")

> suffStat <- list(C = cor(gmL$x), n = nrow(gmL$x))

> fci.gmL <- fci(suffStat, indepTest = gaussCItest, 
+     alpha = 0.9999, labels = c("2", "3", "4", "5"))

> stopifnot(require(Rgraphviz))

> par(mfrow = c(1, 2))

> plot(gmL$g)

> box(col = "gray")

> plot(fci.gmL)

> box(col = "gray")

> suffStat <- list(C = cor(gmL$x), n = nrow(gmL$x))

> fciPlus.gmL <- fciPlus(suffStat, indepTest = gaussCItest, 
+     alpha = 0.9999, labels = c("2", "3", "4", "5"))

> showF(ges)
ges(score, labels = score$getNodes(), 
    fixedGaps = NULL, adaptive = c("none", 
        "vstructures", "triples"), phase = c("forward", 
        "backward", "turning"), iterate = length(phase) > 
        1, turning = NULL, maxDegree = integer(0), 
    verbose = FALSE, ...)  

> score <- new("GaussL0penObsScore", gmG8$x)

> ges.fit <- ges(score)

> par(mfrow = 1:2)

> plot(gmG8$g, main = "")

> box(col = "gray")

> plot(ges.fit$essgraph, main = "")

> box(col = "gray")

> data(gmInt)

> n.tot <- length(gmInt$target.index)

> n.obs <- sum(gmInt$target.index == 1)

> n3 <- sum(gmInt$target.index == 2)

> n5 <- sum(gmInt$target.index == 3)

> showF(gies, width = 60)
gies(score, labels = score$getNodes(), targets = score$getTargets(), 
    fixedGaps = NULL, adaptive = c("none", "vstructures", 
        "triples"), phase = c("forward", "backward", 
        "turning"), iterate = length(phase) > 1, turning = NULL, 
    maxDegree = integer(0), verbose = FALSE, ...)  

> score <- new("GaussL0penIntScore", gmInt$x, targets = gmInt$targets, 
+     target.index = gmInt$target.index)

> gies.fit <- gies(score)

> simy.fit <- simy(score)

> par(mfrow = c(1, 3))

> plot(gmInt$g, main = "")

> box(col = "gray")

> plot(gies.fit$essgraph, main = "")

> box(col = "gray")

> plot(simy.fit$essgraph, main = "")

> box(col = "gray")

> score <- new("GaussL0penObsScore", gmG8$x)

> suffStat <- list(C = cor(gmG8$x), n = nrow(gmG8$x))

> skel.fit <- skeleton(suffStat = suffStat, indepTest = gaussCItest, 
+     alpha = 0.01, p = ncol(gmG8$x))

> skel <- as(skel.fit@graph, "matrix")

> ges.fit <- ges(score, fixedGaps = !skel)

> score <- new("GaussL0penObsScore", gmG8$x)

> library(huge)

> huge.path <- huge(gmG8$x, verbose = FALSE)

> huge.fit <- huge.select(huge.path, verbose = FALSE)

> cig <- as.matrix(huge.fit$refit)

> ges.fit <- ges(score, fixedGaps = !cig, adaptive = "vstructures")

> set.seed(1234)

> n <- 500

> eps1 <- sign(rnorm(n)) * sqrt(abs(rnorm(n)))

> eps2 <- runif(n) - 0.5

> x2 <- 3 + eps2

> x1 <- 0.9 * x2 + 7 + eps1

> X <- cbind(x1, x2)

> res <- lingam(X)

> res
$Bpruned
     [,1]      [,2]
[1,]    0 0.9105471
[2,]    0 0.0000000

$stde
[1] 0.8464599 0.2802133

$ci
[1] 6.922077 3.010565

attr(,"class")
[1] "LINGAM"

> showF(addBgKnowledge)
addBgKnowledge(gInput, x = c(), y = c(), verbose = FALSE, 
    checkInput = TRUE)  

> amat <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0), 3, 3)

> colnames(amat) <- rownames(amat) <- letters[1:3]

> bg <- addBgKnowledge(gInput = amat, x = "a", y = "b")

> par(mfrow = c(1, 2))

> plot(as(t(amat), "graphNEL"))

> box(col = "gray")

> plot(as(t(bg), "graphNEL"))

> box(col = "gray")

> showF(ida)
ida(x.pos, y.pos, mcov, graphEst, method = c("local", 
    "optimal", "global"), y.notparent = FALSE, 
    verbose = FALSE, all.dags = NA, type = c("cpdag", 
        "pdag"))  

> set.seed(123)

> p <- 7

> myDAG <- randomDAG(p, prob = 0.2)

> myCPDAG <- dag2cpdag(myDAG)

> n <- 10000

> dat <- rmvDAG(n, myDAG)

> suffStat <- list(C = cor(dat), n = n)

> pc.fit <- pc(suffStat, indepTest = gaussCItest, p = p, 
+     alpha = 0.01)

> (l.ida.cpdag <- ida(2, 5, cov(dat), myCPDAG, method = "local", 
+     type = "cpdag"))
[1] 0.1748347

> (g.ida.cpdag <- ida(2, 5, cov(dat), myCPDAG, method = "global", 
+     type = "cpdag"))
[1] 0.1748347

> if (require(Rgraphviz)) {
+     par(mfrow = c(1, 2))
+     plot(myDAG, main = "True DAG")
+     box(col = "gray")
+     plot(pc.fit, main = "Estimat ..." ... [TRUNCATED] 

> p <- 6

> V <- as.character(1:p)

> edL <- list(`1` = list(edges = c(3, 4), weights = c(1.1, 
+     0.3)), `2` = list(edges = c(6), weights = c(0.4)), `3` = list(edges = c(2, 
+     4, .... [TRUNCATED] 

> myDAG <- new("graphNEL", nodes = V, edgeL = edL, edgemode = "directed")

> myCPDAG <- dag2cpdag(myDAG)

> covTrue <- trueCov(myDAG)

> (resExactDAG <- jointIda(x.pos = c(1, 2), y.pos = 6, 
+     mcov = covTrue, graphEst = myDAG, technique = "RRC"))
     [,1]
[1,] 0.99
[2,] 0.40

> (resExactCPDAG <- jointIda(x.pos = c(1, 2), y.pos = 6, 
+     mcov = covTrue, graphEst = myCPDAG, technique = "RRC"))
     [,1]          [,2] [,3]
[1,] 0.99 -1.124101e-15 0.99
[2,] 0.40  4.000000e-01 0.40

> par(mfrow = c(1, 2))

> plot(myDAG)

> box(col = "gray")

> plot(myCPDAG)

> box(col = "gray")

> showF(backdoor)
backdoor(amat, x, y, type = "pag", max.chordal = 10, 
    verbose = FALSE)  

> p <- 6

> amat <- t(matrix(c(0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 
+     1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 
+     0, 0, 0, 0, 0, 0), 6, 6))

> V <- as.character(1:6)

> colnames(amat) <- rownames(amat) <- V

> edL <- vector("list", length = 6)

> names(edL) <- V

> edL[[1]] <- list(edges = c(3, 4, 6), weights = c(1, 
+     1, 1))

> edL[[2]] <- list(edges = c(3, 4, 6), weights = c(1, 
+     1, 1))

> edL[[3]] <- list(edges = 5, weights = c(1))

> edL[[4]] <- list(edges = c(5, 6), weights = c(1, 1))

> g <- new("graphNEL", nodes = V, edgeL = edL, edgemode = "directed")

> cov.mat <- trueCov(g)

> myCPDAG <- dag2cpdag(g)

> true.amat <- as(myCPDAG, "matrix")

> par(mfrow = c(1, 2))

> plot(g, main = "")

> box(col = "gray")

> plot(myCPDAG, main = "")

> box(col = "gray")

> backdoor(true.amat, 6, 3, type = "cpdag")
[1] 1 2

> showF(gac)
gac(amat, x, y, z, type = "pag")  

> mFig1 <- matrix(c(0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 
+     0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 
+     0, 0, 0, 0, 0, 0), 6, 6)

> type <- "cpdag"

> x <- 3

> y <- 6

> gac(mFig1, x, y, z = c(2, 4), type)
$gac
[1] TRUE

$res
[1] TRUE TRUE TRUE

$f
[1] 6


> mFig3a <- matrix(c(0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 
+     1, 0, 0, 1, 0), 4, 4)

> type <- "pdag"

> x <- 2

> y <- 4

> str(gac(mFig3a, x, y, z = NULL, type))
List of 3
 $ gac: logi TRUE
 $ res: logi [1:3] TRUE TRUE TRUE
 $ f  : num [1:2] 3 4

> if (require(Rgraphviz)) {
+     colnames(mFig1) <- rownames(mFig1) <- as.character(1:6)
+     g1 <- as(t(mFig1), "graphNEL")
+     colnames(mFig3a)  .... [TRUNCATED] 

> showF(adjustment)
adjustment(amat, amat.type, x, y, set.type)  

> n <- 100

> d <- 3

> s <- 2

> myWgtFun <- function(m, mu, sd) {
+     rnorm(m, mu, sd)
+ }

> set.seed(42)

> dag1 <- randDAG(n = n, d = d, method = "er", DAG = TRUE)

> dag2 <- randDAG(n = n, d = d, method = "power", DAG = TRUE)

> w1 <- wgtMatrix(dag1)

> deg1 <- apply(w1 + t(w1), 2, function(x) sum(x != 
+     0))

> max1 <- max(deg1)

> mean1 <- mean(deg1)

> w2 <- wgtMatrix(dag2)

> deg2 <- apply(w2 + t(w2), 2, function(x) sum(x != 
+     0))

> max2 <- max(deg2)

> mean2 <- mean(deg2)

> n <- 100

> d <- 3

> s <- 2

> myWgtFun <- function(m, mu, sd) {
+     rnorm(m, mu, sd)
+ }

> set.seed(42)

> dag1 <- randDAG(n = n, d = d, method = "er", DAG = TRUE, 
+     weighted = TRUE, wFUN = list(myWgtFun, 0, s))

> dag2 <- randDAG(n = n, d = d, method = "power", DAG = TRUE, 
+     weighted = TRUE, wFUN = list(myWgtFun, 0, s))

> as(pc.gmG8, "amat")
Adjacency Matrix 'amat' (8 x 8) of type 'cpdag':
       Author Bar Ctrl Goal V5 V6 V7 V8
Author      .   1    .    .  .  .  .  .
Bar         1   .    1    .  .  .  .  .
Ctrl        .   1    .    .  .  .  .  .
Goal        .   .    .    .  .  .  .  .
V5          .   1    .    .  .  .  .  .
V6          1   .    .    .  1  .  .  .
V7          .   .    .    .  .  1  .  .
V8          1   .    .    .  1  .  .  .

> m1 <- matrix(c(0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 
+     0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+     0, 0, 0, 0, 0), 6, 6)

> str(gac(m1, x = 1, y = 3, z = NULL, type = "dag"))
List of 3
 $ gac: logi TRUE
 $ res: logi [1:3] TRUE TRUE TRUE
 $ f  : num [1:4] 2 3 5 6

> n <- nrow(gmG8$x)

> V <- colnames(gmG8$x)

> amat <- wgtMatrix(gmG8$g)

> amat[amat != 0] <- 1

> if (requireNamespace("dagitty")) {
+     dagitty_dag1 <- pcalg2dagitty(amat, V, type = "dag")
+     dagitty::is.dagitty(dagitty_dag1)
+ }
Loading required namespace: dagitty
[1] TRUE

> set.seed(42)

> p <- 4

> myDAG <- randomDAG(p, prob = 0.4)

> myCPDAG <- dag2cpdag(myDAG)

> suffStat <- list(C = cov2cor(trueCov(myDAG)), n = 10^9)

> fci.fit <- fci(suffStat, indepTest = gaussCItest, 
+     alpha = 0.9999, p = p, doPdsep = FALSE)

> if (require(Rgraphviz)) {
+     par(mfrow = c(1, 2))
+     plot(myCPDAG)
+     box(col = "gray")
+     plot(fci.fit)
+     box(col = "gray")
+ }

> data(gmG)

> n <- nrow(gmG8$x)

> V <- colnames(gmG8$x)

> pc.fit <- pc(suffStat = list(C = cor(gmG8$x), n = n), 
+     indepTest = gaussCItest, alpha = 0.01, labels = V, verbose = FALSE)

> if (require(igraph)) {
+     par(mfrow = c(1, 1))
+     iplotPC(pc.fit)
+ }
Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:graph':

    degree, edges, intersection, union

The following objects are masked from 'package:BiocGenerics':

    normalize, path, union

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union


> as(pc.fit, "amat")
Adjacency Matrix 'amat' (8 x 8) of type 'cpdag':
       Author Bar Ctrl Goal V5 V6 V7 V8
Author      .   1    .    .  .  .  .  .
Bar         1   .    1    .  .  .  .  .
Ctrl        .   1    .    .  .  .  .  .
Goal        .   .    .    .  .  .  .  .
V5          .   1    .    .  .  .  .  .
V6          1   .    .    .  1  .  .  .
V7          .   .    .    .  .  1  .  .
V8          1   .    .    .  1  .  .  .

> as(fci.fit, "amat")
Adjacency Matrix 'amat' (4 x 4) of type 'pag':
  1 2 3 4
1 . 1 . 2
2 1 . . 2
3 . . . 2
4 1 1 1 .

> showEdgeList(pc.fit)

Edge List: 

Undirected Edges:
  Author  ---  Bar 
  Bar  ---  Ctrl 

Directed Edges:
  Author  -->  V6 
  Author  -->  V8 
  Bar  -->  V5 
  V5  -->  V6 
  V5  -->  V8 
  V6  -->  V7 

> possible_p <- c(seq(5, 10, by = 1))

> possible_neighb_size <- c(1:3)

> num_settings <- 10

> num_rep <- 2

> pb <- seq(0, 1, by = 0.5)

> revealEdge <- function(c, d, s) {
+     if (!anyNA(s)) {
+         for (i in 1:nrow(s)) {
+             c[s[i, 1], s[i, 2]] <- d[s[i, 1], s[i, 2]]
+ .... [TRUNCATED] 

> resFin <- vector("list", num_settings)

> for (r in 1:num_settings) {
+     set.seed(r)
+     p <- sample(possible_p, 1)
+     neigh <- sample(possible_neighb_size, 1)
+     prob <- round(ne .... [TRUNCATED] 
Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable

Graph is not amenable


> nn <- sum(sapply(resFin, length))

> nBG <- length(pb)

> x <- rep(NA, nn * nBG)

> df1 <- data.frame(setting = x, g = x, p = x, neigh = x, 
+     pb = x, resAdj = x, idaNum = x, idaRange = x, timeIda = x, 
+     timeBida = x, trueE .... [TRUNCATED] 

> ii <- 0

> for (i1 in 1:length(resFin)) {
+     nLE <- length(resFin[[i1]])
+     for (i2 in 1:nLE) {
+         for (i3 in 1:nBG) {
+             ii <- ii + 1
 .... [TRUNCATED] 

> tm1 <- tapply(X = df1$resAdj, INDEX = as.factor(df1$pb), 
+     FUN = mean)

> ts1 <- tapply(X = df1$resAdj, INDEX = as.factor(df1$pb), 
+     FUN = function(x) sd(x)/sqrt(length(x)))

> dfNZ <- subset(df1, subset = (trueEff != 0))

> tm <- c(tm1, tapply(X = dfNZ$resAdj, INDEX = as.factor(dfNZ$pb), 
+     FUN = mean))

> ts <- c(ts1, tapply(X = dfNZ$resAdj, INDEX = as.factor(dfNZ$pb), 
+     FUN = function(x) sd(x)/sqrt(length(x))))

> dfID <- data.frame(pb = as.factor(names(tm)), fit = tm, 
+     se = ts, TrueEffect = as.factor(c(rep("All", length(tm)/2), 
+         rep("Non-zero" .... [TRUNCATED] 

> if (require(ggplot2)) {
+     k <- ggplot(dfID, aes(pb, fit, ymin = fit - se, ymax = fit + 
+         se, col = TrueEffect))
+     k + geom_pointran .... [TRUNCATED] 
Loading required package: ggplot2
Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called 'ggplot2'

> nn <- length(pb)

> idx <- rep(seq(1, nrow(df1), by = nn), each = nn)

> nmbIda <- df1$idaNum[idx]

> dfNU2 <- df1[nmbIda > 1, ]

> bnTmp <- cut(x = dfNU2$idaNum, breaks = c(0, 1, 2, 
+     3, 4, 1e+09), labels = c("1", "2", "3", "4", "5+"))

> dfNU2$idaNumF <- factor(bnTmp, levels = levels(bnTmp)[5:1])

> df3 <- dfNU2[, c("pb", "idaNumF")]

> df3$idx <- 1:nrow(df3)

> df3N <- aggregate(idx ~ pb + idaNumF, data = df3, 
+     FUN = length)

> df3N$idaNumF <- droplevels(df3N$idaNumF)

> ggplot(df3N, aes(x = pb, y = idx, fill = idaNumF)) + 
+     geom_bar(stat = "identity") + ylab("Number of simulation settings") + 
+     xlab("Propo ..." ... [TRUNCATED] 

  When sourcing 'vignette2018.R':
Error: could not find function "ggplot"
Execution halted

  'pcalgDoc.Rnw' using 'UTF-8'... OK
  'vignette2018.Rnw' using 'UTF-8'... failed