Skip to content

Commit

Permalink
Fix test and make warning regex more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ash committed Sep 16, 2024
1 parent eb3d7d7 commit 4b1d042
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions R/car.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create_adj_matrix <- function(sh) {
message_regexp = "although coordinates are longitude/latitude, st_intersects assumes that they are planar",
warning_regexp = c(
"some observations have no neighbours",
"neighbour object has 2 sub-graphs")
"neighbour object has \\d+ sub-graphs")
)
adj <- spdep::nb2mat(nb, style = "B", zero.policy = TRUE)
colnames(adj) <- rownames(adj)
Expand Down Expand Up @@ -83,7 +83,7 @@ scale_gmrf_precision <- function(Q,
## but the neighbours list does not depend on it.
nb <- suppress_conditions(
spdep::mat2listw(abs(Q), style = "B", zero.policy = TRUE)$neighbours,
warning_regexp = "neighbour object has 2 sub-graphs"
warning_regexp = "neighbour object has \\d+ sub-graphs"
)
comp <- spdep::n.comp.nb(nb)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ test_that("suppress_conditions works as expected", {
expect_silent(suppress_conditions(f_both(1),
message_regexp = "msg 1",
warning_regexp = "Raising 1"))
expect_warning(suppress_conditions(f(1), message_regexp = "msg 1"),
expect_warning(suppress_conditions(f_both(1), message_regexp = "msg 1"),
"^Raising 1$")
expect_message(suppress_conditions(f(1), warning_regexp = "Raising 1"),
expect_message(suppress_conditions(f_both(1), warning_regexp = "Raising 1"),
"^msg 1\n$")
})

Expand Down

0 comments on commit 4b1d042

Please sign in to comment.