Error: An error occured when interpreting the formula of node 'B'. The message was:
Error: Error in `[.data.table`(mod_mat, , args$parents, with = FALSE): column(s) not found: [A, C]
This error may occur when one of the terms in a supplied formula does not match any variables in the generated data.
 Please check whether all terms in your supplied formula occur in the data generated up to this point.
 The variables currently available in data are:
(Intercept), ATRUE, B, .id

"sex" = rbinom(n = 200, size = 1, prob = 0.7))
prob_sick1 <- function(data, rr_sex0, rr_sex1) {
risk <- fifelse(data$sex == 0, rr_sex0, rr_sex1)
prob_sick2 <- function(data, rr_sex0, rr_sex1) {
base_p[data$age >= 0 & data$age < 12] <- 0.001
"t = 1 node = sickness2\\nt = 1 node = sickness1")
sim_dat_all <- sim_discrete_time(t0_data = dt,
sim_dat_t <- sim_discrete_time(t0_data = dt,
test_that("error when not a DAG object", {
test_that("helpful error message node processing working", {
# function that purposefully throws an error at t = 100
prob_car_crash <- function(data, sim_time, base_p) {
paste0("An error occured when processing node 'car_crash'",
" at time t = 100. The message was:\nError in (",
"function (data, sim_time, base_p) : Error at",
test_that("helpful error message adding node to data working", {
node_nonsense <- function(data, sim_time) {
paste0("An error occured when trying to add the output of ",
"node 'custom_nonsense' at time t = 100 to the ",
"current data. The message was:\nError in ",
"`[<-.data.table`(`*tmp*`, , name, value = list(20, ",
"12)): Supplied 2 items to be assigned to 10 items ",
"of column 'custom_nonsense'. If you wish to ",
"'recycle' the RHS please use rep() to make this ",
"intent clear to readers of your code."),
test_that("helpful error message when processing tx_transform_fun", {
paste0("An error occured when calling the tx_transform() ",
"function at t = 1. The message was:\nError in ",
"(function (data) : failed instantly"), fixed=TRUE)
node_sim_time_multiplier <- function(data, sim_time) {
sim <- sim_discrete_time(dag=dag, n_sim=100, max_t=20)
sim_time_multiplier <- function(data, sim_time) {
node("B", type="rbernoulli", p=0.5, output="numeric") +
node("C", type="rcategorical", probs=c(0.3, 0.2, 0.5),
output="factor", labels=c("low", "medium", "high")) +
node_td("D", type="gaussian", formula= ~ -2 + A*1 + B*3, error=2)
sim <- sim_discrete_time(dag, n_sim=100, max_t=50)
test_that("helpful error message formula error", {
node_td("B", type="gaussian", formula= ~ -1 + A*2 + C*3)
paste0("An error occured when interpreting the formula of ",
"node 'B'. The message was:\nError: Error: column(s) not ",
"found: [A, C]\nThis error may occur when one of the terms ",
"in a supplied ", "formula does not match any variables ",
"in the generated data.\n Please check whether all terms ",
"in your supplied formula occur in the data generated up ",
"to this point.\n The variables currently available in ",