# \donttest{
library(data.table)
# 1. Create dummy data (Fixed: wrapped in factor() for bnlearn)
DT <- data.table(
I_cat = factor(sample(c("Low", "Medium", "High"), 100, replace = TRUE)),
C_cat = factor(sample(c("Low", "Medium", "High"), 100, replace = TRUE)),
Regime = factor(sample(c("Growth", "Crisis"), 100, replace = TRUE))
)
# 2. Define global paths using tempdir()
tmp_dir <- tempdir()
dir_csv <- file.path(tmp_dir, "csv")
dir_out <- file.path(tmp_dir, "dbn")
dir_figs <- file.path(tmp_dir, "figs")
dir.create(dir_csv, showWarnings = FALSE, recursive = TRUE)
dir.create(dir_out, showWarnings = FALSE, recursive = TRUE)
dir.create(dir_figs, showWarnings = FALSE, recursive = TRUE)
# 3. Run the function
dbn_res <- run_dbn(DT)
# Inspect the result
print(dbn_res$dag)
# }
Run the code above in your browser using DataLab