Home > OS >  Suppressing causal tree to print in console
Suppressing causal tree to print in console

Time:07-19

I am using the causalTree package. When I launch the causalTree function, something is printed in the console.

library(causalTree)

n <- 1000
p <- 2
y <- rnorm(n)
X <- matrix(rnorm(n * p), ncol = p)
D <- rbinom(n, 1, 0.5)

tree <- causalTree(y ~ ., data = data.frame(y, X), treatment = D, split.Rule = "CT", cv.option = "CT", split.Honest = T, cv.Honest = T, split.Bucket = F, xval = 5, cp = 0, minsize = 20, propensity = 0.5)

# [1] 2
# [1] "CT"

Is there a way to avoid this?

CodePudding user response:

Probably the causalTree has multiple print statements. You can prevent this to use invisible(capture.output(...)) like this:

library(causalTree)

n <- 1000
p <- 2
y <- rnorm(n)
X <- matrix(rnorm(n * p), ncol = p)
D <- rbinom(n, 1, 0.5)

invisible(capture.output(tree <- causalTree(y ~ ., data = data.frame(y, X), 
                                           treatment = D, split.Rule = "CT", 
                                           cv.option = "CT", split.Honest = T, 
                                           cv.Honest = T, split.Bucket = F, xval = 5, 
                                           cp = 0, minsize = 20, propensity = 0.5)))

Created on 2022-07-19 by the reprex package (v2.0.1)

  • Related