diff --git a/tests/testthat/_snaps/add_stat.md b/tests/testthat/_snaps/add_stat.md index 9a28e5c30..b8cee68b4 100644 --- a/tests/testthat/_snaps/add_stat.md +++ b/tests/testthat/_snaps/add_stat.md @@ -38,3 +38,38 @@ Error in `add_stat()`: ! The `x` argument must be class , not a data frame. +# add_stat() with curly braces in errors/warnings + + Code + curly_warning <- (function(x, ...) { + warning("{curly} warning") + 10 + }) + as.data.frame(add_stat(tbl, fns = ~curly_warning)) + Message + There was a warning for variable "age" + ! {curly} warning + There was a warning for variable "marker" + ! {curly} warning + Output + **Characteristic** **Drug A** \nN = 98 **Drug B** \nN = 102 add_stat_1 + 1 Age 46 (37, 60) 48 (39, 56) 10.0 + 2 Marker Level (ng/mL) 0.84 (0.23, 1.60) 0.52 (0.18, 1.21) 10.0 + +--- + + Code + curly_error <- (function(x, ...) { + stop("{curly} error") + }) + as.data.frame(add_stat(tbl, fns = ~curly_error)) + Message + There was a error for variable "age" + x {curly} error + There was a error for variable "marker" + x {curly} error + Output + **Characteristic** **Drug A** \nN = 98 **Drug B** \nN = 102 add_stat_1 + 1 Age 46 (37, 60) 48 (39, 56) + 2 Marker Level (ng/mL) 0.84 (0.23, 1.60) 0.52 (0.18, 1.21) + diff --git a/tests/testthat/test-add_stat.R b/tests/testthat/test-add_stat.R index b39290af0..b5a453d66 100644 --- a/tests/testthat/test-add_stat.R +++ b/tests/testthat/test-add_stat.R @@ -241,4 +241,22 @@ test_that("add_stat() with tbl_svysummary()", { ) }) +test_that("add_stat() with curly braces in errors/warnings", { + expect_snapshot({ + curly_warning <- \(x, ...) { + warning("{curly} warning"); 10 + } + tbl |> + add_stat(fns = ~ curly_warning) |> + as.data.frame() + }) + expect_snapshot({ + curly_error <- \(x, ...) { + stop("{curly} error") + } + tbl |> + add_stat(fns = ~ curly_error) |> + as.data.frame() + }) +})