From 01ea7478dc34212cf064a48ba09bd4c2dcb26633 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:18:00 +0100 Subject: [PATCH 1/6] spurious(?) viewport-too-small error with new ggplot2 version 3.5.0 Fixes #691 --- R/helpers.R | 6 +++++- tests/testthat/test-helpers.R | 11 +++++++++++ tests/testthat/test-r2_nagelkerke.R | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test-helpers.R diff --git a/R/helpers.R b/R/helpers.R index 3032ffa32..3ac338d97 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -1,6 +1,10 @@ # small wrapper around this commonly used try-catch .safe <- function(code, on_error = NULL) { - tryCatch(code, error = function(e) on_error) + if (getOption("easystats_erros", FALSE) && is.null(on_error)) { + code + } else { + tryCatch(code, error = function(e) on_error) + } } diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R new file mode 100644 index 000000000..f0b5448f3 --- /dev/null +++ b/tests/testthat/test-helpers.R @@ -0,0 +1,11 @@ +skip_if_not_installed("withr") +withr::with_options( + list(easystats_erros = TRUE), + test_that(".safe works with options", { + expect_error(performance:::.safe(mean(fd)), regex = "object 'fd' not found") + expect_identical(performance:::.safe(mean(fd), 1L), 1L) + }) +) +test_that(".safe works", { + expect_null(performance:::.safe(mean(fd))) +}) diff --git a/tests/testthat/test-r2_nagelkerke.R b/tests/testthat/test-r2_nagelkerke.R index 488a46e95..7fa42c8d9 100644 --- a/tests/testthat/test-r2_nagelkerke.R +++ b/tests/testthat/test-r2_nagelkerke.R @@ -4,6 +4,8 @@ test_that("r2_nagelkerke", { expect_equal(r2(model), list(R2_Tjur = c(`Tjur's R2` = 0.477692621360749)), tolerance = 1e-3, ignore_attr = TRUE) }) +skip_if_not_installed("withr") + test_that("r2_nagelkerke", { skip_if_not_installed("MASS") withr::with_options( From cdcd47a21e4922a18e15c2a0489a03a29e922e0c Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:18:21 +0100 Subject: [PATCH 2/6] descr --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 240028ea5..baa900b13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.9.3 +Version: 0.10.9.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", From f6c86b817eb6af54c87443fdebad6e3ee083fe04 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:21:07 +0100 Subject: [PATCH 3/6] test --- tests/testthat/test-helpers.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index f0b5448f3..1283fe944 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -4,8 +4,10 @@ withr::with_options( test_that(".safe works with options", { expect_error(performance:::.safe(mean(fd)), regex = "object 'fd' not found") expect_identical(performance:::.safe(mean(fd), 1L), 1L) + expect_identical(performance:::.safe(mean(c(1, 2, 3))), 2) }) ) test_that(".safe works", { expect_null(performance:::.safe(mean(fd))) + expect_identical(performance:::.safe(mean(c(1, 2, 3))), 2) }) From a1434c6f52653ef3a835c1d6f817af55e3f08bf3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:21:26 +0100 Subject: [PATCH 4/6] skip on cran --- tests/testthat/test-helpers.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index 1283fe944..d1d6a5545 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -1,3 +1,4 @@ +skip_on_cran() skip_if_not_installed("withr") withr::with_options( list(easystats_erros = TRUE), From dda878c2d308874078d51764119b2852cc15c92f Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:33:58 +0100 Subject: [PATCH 5/6] lintr --- R/helpers.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 3ac338d97..5c297752f 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -69,10 +69,10 @@ .get_sigma <- function(model, verbose = TRUE) { s <- insight::get_sigma(model, ci = NULL, verbose = verbose) - if (!is.null(s)) { - as.numeric(s) - } else { + if (is.null(s)) { NULL + } else { + as.numeric(s) } } From c7051b15a5304a005642f553861ff27362de3c9c Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 Mar 2024 21:34:33 +0100 Subject: [PATCH 6/6] code style --- R/helpers.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/R/helpers.R b/R/helpers.R index 5c297752f..c231d6226 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -38,13 +38,10 @@ if (!is.numeric(x)) { return(x) } - # remove missings tmp <- x[!is.na(x)] - # standardize tmp <- (tmp - mean(tmp)) / stats::sd(tmp) - # and fill in values in original vector x[!is.na(x)] <- tmp