I've found myself occasionally entering an incorrect variable name into the analysis functions. When one does that, dagitty produces a bit of a mysterious error message, e.g.
library(dagitty)
g <- dagitty("dag{x <- z -> y}")
# accidentally capitalize "x"
ancestors(g, "X")
#> Error in context_eval(join(src), private$context): TypeError: Cannot read property 'traversal_info' of undefined
I think it would be nice if it were clearer, e.g. in ancestors, do something like
check_dag_names <- function(x, v) {
if (!(v %in% names(x)))
stop(paste(v, "is not a variable in `x`"))
}
check_dag_names(g, "X")
#> Error in check_dag_names(g, "X"): X is not a variable in `x`
ancestors <- function(x, v) {
check_dag_names(x, v)
.kins(x, v, "ancestors")
}
What do you think? I could send a PR for the functions that accept variable names, if you'd like.
Hi Johannes,
I've found myself occasionally entering an incorrect variable name into the analysis functions. When one does that,
dagitty
produces a bit of a mysterious error message, e.g.I think it would be nice if it were clearer, e.g. in ancestors, do something like
What do you think? I could send a PR for the functions that accept variable names, if you'd like.