From 4b1d042839dfced5b70abb0b3199ca0bc87fefb4 Mon Sep 17 00:00:00 2001 From: Rob Ashton Date: Mon, 16 Sep 2024 14:05:22 +0100 Subject: [PATCH] Fix test and make warning regex more robust --- R/car.R | 4 ++-- tests/testthat/test-utils.R | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/car.R b/R/car.R index 48c28687..1c74277a 100644 --- a/R/car.R +++ b/R/car.R @@ -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) @@ -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) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 98317777..e9eda56a 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -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$") })