Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 1, 2024
1 parent 22971d6 commit 35cd5d5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions R/check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,13 @@ check_dag <- function(...,
adjustment_set <- unlist(dagitty::adjustmentSets(dag, effect = x), use.names = FALSE)
adjustment_nodes <- unlist(dagitty::adjustedNodes(dag), use.names = FALSE)
minimal_adjustments <- as.list(dagitty::adjustmentSets(dag, effect = x))
collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)]
if (!length(collider)) {
collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)] # nolint
if (length(collider)) {
# if we *have* colliders, remove them from minimal adjustments
minimal_adjustments <- lapply(minimal_adjustments, setdiff, y = collider)
} else {
# if we don't have colliders, set to NULL
collider <- NULL
} else {
# if we *have* colliders, remove them from minimal adjustments
minimal_adjustments <- lapply(minimal_adjustments, function(ma) {
setdiff(ma, collider)
})
}
list(
# no adjustment needed when
Expand All @@ -303,7 +301,7 @@ check_dag <- function(...,
# incorrect adjustment when
# - required is NULL and current adjustment not NULL
# - OR we have a collider in current adjustments
incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes),
incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes), # nolint
current_adjustments = adjustment_nodes,
minimal_adjustments = minimal_adjustments,
collider = collider
Expand Down

0 comments on commit 35cd5d5

Please sign in to comment.