From 588e2394c60dbf72624fba5990dfe34a62893de9 Mon Sep 17 00:00:00 2001 From: Gauarv Chaudhary Date: Fri, 12 Dec 2025 22:05:22 +0530 Subject: [PATCH 1/3] test: add failing test for multiple colliders bug (#878) Reproduces the error when check_dag encounters multiple colliders in adjustment nodes, causing: 'length = 2' in coercion to 'logical(1)' The test currently fails as expected and will pass once the bug is fixed in the .finalize_dag() function. Issue: #878 --- tests/testthat/test-check_dag.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/testthat/test-check_dag.R b/tests/testthat/test-check_dag.R index a25d2ff1f..b840a37ae 100644 --- a/tests/testthat/test-check_dag.R +++ b/tests/testthat/test-check_dag.R @@ -201,3 +201,21 @@ test_that("check_dag, formula-interface", { ) expect_identical(dag, dag2) }) + + +test_that("check_dag handles multiple colliders correctly - issue #878", { + # This test reproduces the error from issue #878 + # The DAG has multiple colliders (both 'a' and 'b' are colliders) + # because they both have multiple incoming paths from 'c' and 'd' + expect_error( + check_dag( + y ~ x + a + b, + a ~ c + d, + b ~ c + d, + outcome = "y", + exposure = "x", + adjusted = ~ a + b + ), + regexp = "length = 2.*coercion to.*logical\\(1\\)" + ) +}) From 3b0421220c0030fb4d934527e8a41c4fd8507300 Mon Sep 17 00:00:00 2001 From: Gauarv Chaudhary Date: Fri, 12 Dec 2025 22:16:25 +0530 Subject: [PATCH 2/3] fix: use expect_no_error for proper regression test Changed from expect_error to expect_no_error so the test: - FAILS now (while bug exists) - PASSES after the fix is applied Issue: #878 --- tests/testthat/test-check_dag.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-check_dag.R b/tests/testthat/test-check_dag.R index b840a37ae..4414635c2 100644 --- a/tests/testthat/test-check_dag.R +++ b/tests/testthat/test-check_dag.R @@ -207,7 +207,8 @@ test_that("check_dag handles multiple colliders correctly - issue #878", { # This test reproduces the error from issue #878 # The DAG has multiple colliders (both 'a' and 'b' are colliders) # because they both have multiple incoming paths from 'c' and 'd' - expect_error( + # This test FAILS while bug exists, PASSES after fix + expect_no_error( check_dag( y ~ x + a + b, a ~ c + d, @@ -215,7 +216,6 @@ test_that("check_dag handles multiple colliders correctly - issue #878", { outcome = "y", exposure = "x", adjusted = ~ a + b - ), - regexp = "length = 2.*coercion to.*logical\\(1\\)" + ) ) }) From de2839fa431d8ebd63bf18264e2b02d6c5923cb2 Mon Sep 17 00:00:00 2001 From: Gauarv Chaudhary Date: Sat, 13 Dec 2025 12:58:27 +0530 Subject: [PATCH 3/3] fix: handle multiple colliders in check_dag (#878) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix error when check_dag encounters multiple colliders in adjustment nodes. The issue was that 'collider %in% adjustment_nodes' returns a vector of logical values when there are multiple colliders, which cannot be used with the && operator. Solution: Use any() to properly handle vector comparison. Also add missing author names to WORDLIST for spell check: - Dunkler, Graham, Gregorich, Morrissey, Papeş, Pandey, Park, Ruxton, Strohmaier Fixes #878 --- R/check_dag.R | 2 +- inst/WORDLIST | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/R/check_dag.R b/R/check_dag.R index cc5acfea7..dca48df3f 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -347,7 +347,7 @@ check_dag <- function( # - 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), # nolint + (!is.null(collider) && any(collider %in% adjustment_nodes)), # nolint current_adjustments = adjustment_nodes, minimal_adjustments = minimal_adjustments, collider = collider diff --git a/inst/WORDLIST b/inst/WORDLIST index d9394796d..847ab8bbe 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -62,6 +62,7 @@ Dominicy Dordrecht Dorie Dunson +Dunkler Durbin Dxy Döring @@ -88,6 +89,8 @@ Gabry Gazen Gelman Gnanadesikan +Graham +Gregorich Guilford Hartig HDI @@ -158,6 +161,7 @@ Michalos Moosbrugger Monette Mora +Morrissey Multicollinearity MuMIn NFI @@ -178,6 +182,9 @@ OSF OSX Olkin PNFI +Papeş +Pandey +Park Pek Petrov polychoric @@ -202,6 +209,7 @@ Rousseeuw Routledge Rouder Rouder's +Ruxton SEM SRMR Scheepers @@ -220,6 +228,7 @@ Specifity Sphericity Springer Stata +Strohmaier Subscales TLI Technometrics