From 8f0646e7d4f78cd60abc9145c469a9438fb06272 Mon Sep 17 00:00:00 2001 From: Dominique Makowski Date: Fri, 3 Jan 2025 21:17:37 +0000 Subject: [PATCH 01/13] Update methods_format.R --- R/methods_format.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/methods_format.R b/R/methods_format.R index e4ab7fe4..f7c0dc46 100644 --- a/R/methods_format.R +++ b/R/methods_format.R @@ -40,6 +40,7 @@ format.easycormatrix <- function(x, stars = NULL, include_significance = NULL, format = NULL, + zap_small = NULL, bf_exact = TRUE, ...) { # If it's a real matrix @@ -56,11 +57,13 @@ format.easycormatrix <- function(x, stars <- .retrieve_arg_from_attr(attri, stars, default = TRUE) include_significance <- .retrieve_arg_from_attr(attri, include_significance, default = FALSE) p_digits <- .retrieve_arg_from_attr(attri, p_digits, default = "apa") + zap_small <- .retrieve_arg_from_attr(attri, zap_small, default = TRUE) # Round and format values nums <- sapply(as.data.frame(x), is.numeric) - x[, nums] <- sapply(as.data.frame(x)[, nums], insight::format_value, digits = digits) + x[, nums] <- sapply(as.data.frame(x)[, nums], insight::format_value, + digits = digits, zap_small = zap_small, ...) # Deduct if stars only From 29d4fdccd1bd90cb09ae3ce5141de25476be0b76 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 22:53:44 +0100 Subject: [PATCH 02/13] news, desc --- DESCRIPTION | 2 +- NEWS.md | 7 +++++++ R/methods_format.R | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7608ca48..bf19581e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: correlation Title: Methods for Correlation Analysis -Version: 0.8.6.1 +Version: 0.8.6.2 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 7a5aa60f..5fea74b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # correlation 0.8.6 +- The `format()` for objects of class `easycormatrix` gets a `zap_small` argument, + which defaults to `TRUE`, to round very small numbers. + +- `cor_sort()` can now deal with non-square matrices. + +# correlation 0.8.6 + - Fix CRAN check issues. # correlation 0.8.5 diff --git a/R/methods_format.R b/R/methods_format.R index f7c0dc46..ecc1af2d 100644 --- a/R/methods_format.R +++ b/R/methods_format.R @@ -40,7 +40,7 @@ format.easycormatrix <- function(x, stars = NULL, include_significance = NULL, format = NULL, - zap_small = NULL, + zap_small = TRUE, bf_exact = TRUE, ...) { # If it's a real matrix From 5b3622c948d24a36c7c072d25b26976875ff845f Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 22:54:40 +0100 Subject: [PATCH 03/13] update snapshots --- tests/testthat/_snaps/as_list.md | 96 ++++++++++++++++---------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/tests/testthat/_snaps/as_list.md b/tests/testthat/_snaps/as_list.md index ab7574f6..6d29e652 100644 --- a/tests/testthat/_snaps/as_list.md +++ b/tests/testthat/_snaps/as_list.md @@ -37,18 +37,18 @@ p --- - Parameter | carb | gear | am | vs | qsec | wt | drat | hp | disp | cyl - ----------------------------------------------------------------------------------------------------------------------- - mpg | 0.02 | 0.10 | 8.27e-03 | 1.09e-03 | 0.22 | 6.86e-09 | 5.86e-04 | 8.05e-06 | 4.78e-08 | 3.18e-08 - cyl | 0.04 | 0.08 | 0.04 | 9.03e-07 | 0.01 | 5.60e-06 | 2.97e-04 | 1.74e-07 | 9.92e-11 | - disp | 0.30 | 0.02 | 0.01 | 2.04e-04 | 0.20 | 6.60e-10 | 2.04e-04 | 3.36e-06 | | - hp | 3.44e-05 | 1.00 | 1.00 | 1.24e-04 | 2.13e-04 | 1.29e-03 | 0.17 | | | - drat | 1.00 | 2.97e-04 | 1.94e-04 | 0.19 | 1.00 | 1.94e-04 | | | | - wt | 0.20 | 0.01 | 3.83e-04 | 0.02 | 1.00 | | | | | - qsec | 1.36e-03 | 1.00 | 1.00 | 4.43e-05 | | | | | | - vs | 0.02 | 1.00 | 1.00 | | | | | | | - am | 1.00 | 2.80e-06 | | | | | | | | - gear | 1.00 | | | | | | | | | + Parameter | carb | gear | am | vs | qsec | wt | drat | hp | disp | cyl + ------------------------------------------------------------------------------- + mpg | 0.02 | 0.10 | 0.01 | 0.00 | 0.22 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 + cyl | 0.04 | 0.08 | 0.04 | 0.00 | 0.01 | 0.00 | 0.00 | 0.00 | 0.00 | + disp | 0.30 | 0.02 | 0.01 | 0.00 | 0.20 | 0.00 | 0.00 | 0.00 | | + hp | 0.00 | 1.00 | 1.00 | 0.00 | 0.00 | 0.00 | 0.17 | | | + drat | 1.00 | 0.00 | 0.00 | 0.19 | 1.00 | 0.00 | | | | + wt | 0.20 | 0.01 | 0.00 | 0.02 | 1.00 | | | | | + qsec | 0.00 | 1.00 | 1.00 | 0.00 | | | | | | + vs | 0.02 | 1.00 | 1.00 | | | | | | | + am | 1.00 | 0.00 | | | | | | | | + gear | 1.00 | | | | | | | | | @@ -85,13 +85,13 @@ p --- - Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem - --------------------------------------------------------------------------- - carni | sleep_total | 0.37 | 0.73 | 0.00 | 1.00 | 3.19e-04 - carni | sleep_rem | 0.20 | 1.00 | 3.19e-04 | 1.00 | - carni | sleep_cycle | 1.00 | 1.00 | 1.00 | | - carni | awake | 0.37 | 0.73 | | | - carni | brainwt | 0.09 | | | | + Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem + ------------------------------------------------------------------------ + carni | sleep_total | 0.37 | 0.73 | 0.00 | 1.00 | 0.00 + carni | sleep_rem | 0.20 | 1.00 | 0.00 | 1.00 | + carni | sleep_cycle | 1.00 | 1.00 | 1.00 | | + carni | awake | 0.37 | 0.73 | | | + carni | brainwt | 0.09 | | | | @@ -123,13 +123,13 @@ p --- - Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem - ------------------------------------------------------------------------------ - herbi | sleep_total | 3.42e-06 | 8.71e-06 | 0.00 | 0.35 | 5.00e-09 - herbi | sleep_rem | 4.65e-04 | 4.43e-03 | 5.00e-09 | 0.35 | - herbi | sleep_cycle | 0.03 | 0.04 | 0.35 | | - herbi | awake | 3.42e-06 | 8.71e-06 | | | - herbi | brainwt | 5.17e-13 | | | | + Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem + ------------------------------------------------------------------------ + herbi | sleep_total | 0.00 | 0.00 | 0.00 | 0.35 | 0.00 + herbi | sleep_rem | 0.00 | 0.00 | 0.00 | 0.35 | + herbi | sleep_cycle | 0.03 | 0.04 | 0.35 | | + herbi | awake | 0.00 | 0.00 | | | + herbi | brainwt | 0.00 | | | | @@ -161,13 +161,13 @@ p --- - Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem - ------------------------------------------------------------------------------- - insecti | sleep_total | 1.00 | 1.00 | 1.46e-22 | 1.00 | 1.00 - insecti | sleep_rem | 1.00 | 1.00 | 1.00 | 0.00 | - insecti | sleep_cycle | 1.00 | 1.00 | 1.00 | | - insecti | awake | 1.00 | 1.00 | | | - insecti | brainwt | 5.56e-23 | | | | + Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem + -------------------------------------------------------------------------- + insecti | sleep_total | 1.00 | 1.00 | 0.00 | 1.00 | 1.00 + insecti | sleep_rem | 1.00 | 1.00 | 1.00 | 0.00 | + insecti | sleep_cycle | 1.00 | 1.00 | 1.00 | | + insecti | awake | 1.00 | 1.00 | | | + insecti | brainwt | 0.00 | | | | @@ -199,13 +199,13 @@ p --- - Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem - --------------------------------------------------------------------------- - omni | sleep_total | 1.00 | 1.00 | 0.00 | 1.00 | 1.00 - omni | sleep_rem | 1.00 | 1.00 | 1.00 | 1.00 | - omni | sleep_cycle | 0.04 | 7.73e-04 | 1.00 | | - omni | awake | 1.00 | 1.00 | | | - omni | brainwt | 7.64e-06 | | | | + Group | Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem + ------------------------------------------------------------------------ + omni | sleep_total | 1.00 | 1.00 | 0.00 | 1.00 | 1.00 + omni | sleep_rem | 1.00 | 1.00 | 1.00 | 1.00 | + omni | sleep_cycle | 0.04 | 0.00 | 1.00 | | + omni | awake | 1.00 | 1.00 | | | + omni | brainwt | 0.00 | | | | @@ -237,10 +237,10 @@ p --- - Group | Parameter | hp - ---------------------------- - 0 | cyl | 2.11e-06 - 0 | wt | 1.11e-05 + Group | Parameter | hp + ------------------------ + 0 | cyl | 0.00 + 0 | wt | 0.00 @@ -266,10 +266,10 @@ p --- - Group | Parameter | hp - ---------------------------- - 1 | cyl | 9.58e-04 - 1 | wt | 1.04e-03 + Group | Parameter | hp + ------------------------ + 1 | cyl | 0.00 + 1 | wt | 0.00 From f11f915410d053860607a826693276444dfde316 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 23:00:40 +0100 Subject: [PATCH 04/13] add test --- R/methods_format.R | 2 +- tests/testthat/_snaps/windows/correlation.md | 28 ++++++++++++++++++++ tests/testthat/test-correlation.R | 13 +++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/windows/correlation.md diff --git a/R/methods_format.R b/R/methods_format.R index ecc1af2d..f7c0dc46 100644 --- a/R/methods_format.R +++ b/R/methods_format.R @@ -40,7 +40,7 @@ format.easycormatrix <- function(x, stars = NULL, include_significance = NULL, format = NULL, - zap_small = TRUE, + zap_small = NULL, bf_exact = TRUE, ...) { # If it's a real matrix diff --git a/tests/testthat/_snaps/windows/correlation.md b/tests/testthat/_snaps/windows/correlation.md new file mode 100644 index 00000000..f902b558 --- /dev/null +++ b/tests/testthat/_snaps/windows/correlation.md @@ -0,0 +1,28 @@ +# correlation output with zap_small + + Code + summary(r) + Output + # Correlation Matrix (pearson-method) + + Parameter | z | y + ----------------------- + x | 0.02 | 0.01 + y | 0.00 | + + p-value adjustment method: Holm (1979) + +--- + + Code + summary(r, zap_small = FALSE) + Output + # Correlation Matrix (pearson-method) + + Parameter | z | y + -------------------------------- + x | 0.02 | 6.02e-03 + y | -3.07e-03 | + + p-value adjustment method: Holm (1979) + diff --git a/tests/testthat/test-correlation.R b/tests/testthat/test-correlation.R index 7478e11c..81b24bcb 100644 --- a/tests/testthat/test-correlation.R +++ b/tests/testthat/test-correlation.R @@ -198,3 +198,16 @@ test_that("as.data.frame for correlation output", { set.seed(123) expect_snapshot(as.data.frame(correlation(ggplot2::msleep))) }) + +test_that("correlation output with zap_small", { + set.seed(123) + d <- data.frame( + x = rnorm(10000), + y = rnorm(10000), + z = rnorm(10000) + ) + r <- correlation::correlation(d) + + expect_snapshot(summary(r), variant = "windows") + expect_snapshot(summary(r, zap_small = FALSE), variant = "windows") +}) From 846ce6495dec80afb6c85b473087c9e6c9b3cc99 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 23:01:26 +0100 Subject: [PATCH 05/13] news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 5fea74b2..2300ac3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # correlation 0.8.6 - The `format()` for objects of class `easycormatrix` gets a `zap_small` argument, - which defaults to `TRUE`, to round very small numbers. + to round very small numbers. - `cor_sort()` can now deal with non-square matrices. From 97d705c0e5a468dca8927195cff6cc290342cbf1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 23:01:39 +0100 Subject: [PATCH 06/13] version --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2300ac3d..d5a773a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# correlation 0.8.6 +# correlation 0.8.7 - The `format()` for objects of class `easycormatrix` gets a `zap_small` argument, to round very small numbers. From 99a70cb0aec8eeca0211836b79a73c377ce1c315 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Jan 2025 23:01:53 +0100 Subject: [PATCH 07/13] news --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index d5a773a3..515646a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # correlation 0.8.7 -- The `format()` for objects of class `easycormatrix` gets a `zap_small` argument, - to round very small numbers. +- The `format()` method for objects of class `easycormatrix` gets a `zap_small` + argument, to round very small numbers. - `cor_sort()` can now deal with non-square matrices. From b7e98248791dc296bd2e5ce89c1788cf95dc8522 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 17:13:31 +0100 Subject: [PATCH 08/13] update tests --- tests/testthat/_snaps/display_print_dataframe.md | 7 ------- tests/testthat/_snaps/display_print_matrix.md | 15 --------------- tests/testthat/_snaps/methods.md | 14 +++++++------- tests/testthat/test-display_print_dataframe.R | 1 - tests/testthat/test-display_print_matrix.R | 5 ++--- 5 files changed, 9 insertions(+), 33 deletions(-) diff --git a/tests/testthat/_snaps/display_print_dataframe.md b/tests/testthat/_snaps/display_print_dataframe.md index dc3c009e..83fb22b7 100644 --- a/tests/testthat/_snaps/display_print_dataframe.md +++ b/tests/testthat/_snaps/display_print_dataframe.md @@ -1,12 +1,5 @@ # display and print method works - markdown - Code - print(correlation(iris), format = "markdown") - Output - Table: Correlation Matrix (pearson-method) |Parameter1 | Parameter2| r | 95% CI | t(148)| p | |:------------|------------:|:-----|:--------------|------:|:---------| |Sepal.Length | Sepal.Width|-0.12 |[-0.27, 0.04] | -1.44|0.152 | |Sepal.Length | Petal.Length| 0.87 |[ 0.83, 0.91] | 21.65|< .001*** | |Sepal.Length | Petal.Width| 0.82 |[ 0.76, 0.86] | 17.30|< .001*** | |Sepal.Width | Petal.Length|-0.43 |[-0.55, -0.29] | -5.77|< .001*** | |Sepal.Width | Petal.Width|-0.37 |[-0.50, -0.22] | -4.79|< .001*** | |Petal.Length | Petal.Width| 0.96 |[ 0.95, 0.97] | 43.39|< .001*** | p-value adjustment method: Holm (1979) Observations: 150 - ---- - Code display(correlation(iris)) Output diff --git a/tests/testthat/_snaps/display_print_matrix.md b/tests/testthat/_snaps/display_print_matrix.md index 31636ba4..f9871940 100644 --- a/tests/testthat/_snaps/display_print_matrix.md +++ b/tests/testthat/_snaps/display_print_matrix.md @@ -16,21 +16,6 @@ attr(,"class") [1] "knitr_kable" "character" ---- - - Code - print(summary(correlation(iris))) - Output - # Correlation Matrix (pearson-method) - - Parameter | Petal.Width | Petal.Length | Sepal.Width - ------------------------------------------------------- - Sepal.Length | 0.82*** | 0.87*** | -0.12 - Sepal.Width | -0.37*** | -0.43*** | - Petal.Length | 0.96*** | | - - p-value adjustment method: Holm (1979) - # as.matrix works Code diff --git a/tests/testthat/_snaps/methods.md b/tests/testthat/_snaps/methods.md index b5fbadd1..0981db4c 100644 --- a/tests/testthat/_snaps/methods.md +++ b/tests/testthat/_snaps/methods.md @@ -39,13 +39,13 @@ Output # Correlation Matrix (pearson-method) - Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem - ----------------------------------------------------------------------- - sleep_total | 0.04 | 0.05 | 3.63e-225 | 0.05 | 3.78e-11 - sleep_rem | 0.05 | 0.13 | 3.78e-11 | 0.12 | - sleep_cycle | 0.05 | 2.66e-08 | 0.05 | | - awake | 0.04 | 0.05 | | | - brainwt | 1.28e-24 | | | | + Parameter | bodywt | brainwt | awake | sleep_cycle | sleep_rem + ---------------------------------------------------------------- + sleep_total | 0.04 | 0.05 | 0.00 | 0.05 | 0.00 + sleep_rem | 0.05 | 0.13 | 0.00 | 0.12 | + sleep_cycle | 0.05 | 0.00 | 0.05 | | + awake | 0.04 | 0.05 | | | + brainwt | 0.00 | | | | p-value adjustment method: Holm (1979) diff --git a/tests/testthat/test-display_print_dataframe.R b/tests/testthat/test-display_print_dataframe.R index 891eb551..6ba7e118 100644 --- a/tests/testthat/test-display_print_dataframe.R +++ b/tests/testthat/test-display_print_dataframe.R @@ -3,7 +3,6 @@ test_that("display and print method works - markdown", { skip_if(getRversion() < "4.0.0") skip_if_not_or_load_if_installed("gt") - expect_snapshot(print(correlation(iris), format = "markdown")) expect_snapshot(display(correlation(iris))) }) diff --git a/tests/testthat/test-display_print_matrix.R b/tests/testthat/test-display_print_matrix.R index a70d5e9e..ea5bf326 100644 --- a/tests/testthat/test-display_print_matrix.R +++ b/tests/testthat/test-display_print_matrix.R @@ -4,7 +4,6 @@ test_that("display and print method works - markdown", { skip_on_cran() skip_if_not_or_load_if_installed("gt") expect_snapshot(display(summary(correlation(iris)))) - expect_snapshot(print(summary(correlation(iris)))) }) # display and print method works - html ----------------------------- @@ -19,11 +18,11 @@ test_that("as.matrix works", { skip_if_not_installed("datawizard") skip_if(getRversion() < "4.1.0") set.seed(123) - mat1 <- select(mtcars, am, wt, hp) |> + mat1 <- datawizard::data_select(mtcars, c("am", "wt", "hp")) |> correlation() |> as.matrix() set.seed(123) - mat2 <- select(mtcars, am, wt, hp) |> + mat2 <- datawizard::data_select(mtcars, c("am", "wt", "hp")) |> datawizard::data_group(am) |> correlation() |> as.matrix() From 4af4d7c5c9ff9a1be52e8f382ffbd7e72cb3112f Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 23:03:10 +0100 Subject: [PATCH 09/13] fix test --- .../_snaps/display_print_dataframe.md | 22 ------------------- tests/testthat/_snaps/display_print_matrix.md | 18 --------------- tests/testthat/test-display_print_dataframe.R | 15 +++++++++---- tests/testthat/test-display_print_matrix.R | 15 +++++++++++-- 4 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 tests/testthat/_snaps/display_print_dataframe.md diff --git a/tests/testthat/_snaps/display_print_dataframe.md b/tests/testthat/_snaps/display_print_dataframe.md deleted file mode 100644 index 83fb22b7..00000000 --- a/tests/testthat/_snaps/display_print_dataframe.md +++ /dev/null @@ -1,22 +0,0 @@ -# display and print method works - markdown - - Code - display(correlation(iris)) - Output - [1] "Table: Correlation Matrix (pearson-method)" - [2] "" - [3] "|Parameter1 | Parameter2 | r | 95% CI | t(148) | p |" - [4] "|:------------|:------------:|:-----:|:--------------:|:------:|:---------:|" - [5] "|Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 |" - [6] "|Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** |" - [7] "|Sepal.Length | Petal.Width | 0.82 | (0.76, 0.86) | 17.30 | < .001*** |" - [8] "|Sepal.Width | Petal.Length | -0.43 | (-0.55, -0.29) | -5.77 | < .001*** |" - [9] "|Sepal.Width | Petal.Width | -0.37 | (-0.50, -0.22) | -4.79 | < .001*** |" - [10] "|Petal.Length | Petal.Width | 0.96 | (0.95, 0.97) | 43.39 | < .001*** |" - [11] "p-value adjustment method: Holm (1979)" - [12] "Observations: 150" - attr(,"format") - [1] "pipe" - attr(,"class") - [1] "knitr_kable" "character" - diff --git a/tests/testthat/_snaps/display_print_matrix.md b/tests/testthat/_snaps/display_print_matrix.md index f9871940..3f2e2085 100644 --- a/tests/testthat/_snaps/display_print_matrix.md +++ b/tests/testthat/_snaps/display_print_matrix.md @@ -1,21 +1,3 @@ -# display and print method works - markdown - - Code - display(summary(correlation(iris))) - Output - [1] "Table: Correlation Matrix (pearson-method)" - [2] "" - [3] "|Parameter | Petal.Width | Petal.Length | Sepal.Width |" - [4] "|:------------|:-----------:|:------------:|:-----------:|" - [5] "|Sepal.Length | 0.82*** | 0.87*** | -0.12 |" - [6] "|Sepal.Width | -0.37*** | -0.43*** | |" - [7] "|Petal.Length | 0.96*** | | |" - [8] "p-value adjustment method: Holm (1979)" - attr(,"format") - [1] "pipe" - attr(,"class") - [1] "knitr_kable" "character" - # as.matrix works Code diff --git a/tests/testthat/test-display_print_dataframe.R b/tests/testthat/test-display_print_dataframe.R index 6ba7e118..7c94c5c6 100644 --- a/tests/testthat/test-display_print_dataframe.R +++ b/tests/testthat/test-display_print_dataframe.R @@ -1,9 +1,16 @@ test_that("display and print method works - markdown", { skip_on_cran() - skip_if(getRversion() < "4.0.0") - skip_if_not_or_load_if_installed("gt") - - expect_snapshot(display(correlation(iris))) + out <- display(correlation(iris)) + expect_identical( + out[1:7], + c( + "Table: Correlation Matrix (pearson-method)", "", "|Parameter1 | Parameter2 | r | 95% CI | t(148) | p |", + "|:------------|:------------:|:-----:|:--------------:|:------:|:---------:|", + "|Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 |", + "|Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** |", + "|Sepal.Length | Petal.Width | 0.82 | (0.76, 0.86) | 17.30 | < .001*** |" + ) + ) }) # display and print method works - HTML ----------------------------- diff --git a/tests/testthat/test-display_print_matrix.R b/tests/testthat/test-display_print_matrix.R index ea5bf326..a333fad0 100644 --- a/tests/testthat/test-display_print_matrix.R +++ b/tests/testthat/test-display_print_matrix.R @@ -2,8 +2,19 @@ test_that("display and print method works - markdown", { skip_on_cran() - skip_if_not_or_load_if_installed("gt") - expect_snapshot(display(summary(correlation(iris)))) + out <- capture.output(display(summary(correlation(iris)))) + expect_identical( + out[1:7], + c( + "[1] \"Table: Correlation Matrix (pearson-method)\" ", + "[2] \"\" ", + "[3] \"|Parameter | Petal.Width | Petal.Length | Sepal.Width |\"", + "[4] \"|:------------|:-----------:|:------------:|:-----------:|\"", + "[5] \"|Sepal.Length | 0.82*** | 0.87*** | -0.12 |\"", + "[6] \"|Sepal.Width | -0.37*** | -0.43*** | |\"", + "[7] \"|Petal.Length | 0.96*** | | |\"" + ) + ) }) # display and print method works - html ----------------------------- From 22bd109b01d853d1afd54bfb2d3f8359d4c33688 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 23:04:11 +0100 Subject: [PATCH 10/13] style --- tests/testthat/test-display_print_dataframe.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-display_print_dataframe.R b/tests/testthat/test-display_print_dataframe.R index 7c94c5c6..d7676a50 100644 --- a/tests/testthat/test-display_print_dataframe.R +++ b/tests/testthat/test-display_print_dataframe.R @@ -4,7 +4,9 @@ test_that("display and print method works - markdown", { expect_identical( out[1:7], c( - "Table: Correlation Matrix (pearson-method)", "", "|Parameter1 | Parameter2 | r | 95% CI | t(148) | p |", + "Table: Correlation Matrix (pearson-method)", + "", + "|Parameter1 | Parameter2 | r | 95% CI | t(148) | p |", "|:------------|:------------:|:-----:|:--------------:|:------:|:---------:|", "|Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 |", "|Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** |", From 2e55cdf0a526ab752ef64e77562c445c3b8eef69 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 23:15:36 +0100 Subject: [PATCH 11/13] fix --- tests/testthat/test-display_print_dataframe.R | 15 ++------------- tests/testthat/test-display_print_matrix.R | 15 ++------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/tests/testthat/test-display_print_dataframe.R b/tests/testthat/test-display_print_dataframe.R index d7676a50..e9234ad8 100644 --- a/tests/testthat/test-display_print_dataframe.R +++ b/tests/testthat/test-display_print_dataframe.R @@ -1,18 +1,7 @@ test_that("display and print method works - markdown", { skip_on_cran() - out <- display(correlation(iris)) - expect_identical( - out[1:7], - c( - "Table: Correlation Matrix (pearson-method)", - "", - "|Parameter1 | Parameter2 | r | 95% CI | t(148) | p |", - "|:------------|:------------:|:-----:|:--------------:|:------:|:---------:|", - "|Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 |", - "|Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** |", - "|Sepal.Length | Petal.Width | 0.82 | (0.76, 0.86) | 17.30 | < .001*** |" - ) - ) + skip_if_not_or_load_if_installed("knitr") + expect_snapshot(display(correlation(iris))) }) # display and print method works - HTML ----------------------------- diff --git a/tests/testthat/test-display_print_matrix.R b/tests/testthat/test-display_print_matrix.R index a333fad0..812cf8ad 100644 --- a/tests/testthat/test-display_print_matrix.R +++ b/tests/testthat/test-display_print_matrix.R @@ -2,19 +2,8 @@ test_that("display and print method works - markdown", { skip_on_cran() - out <- capture.output(display(summary(correlation(iris)))) - expect_identical( - out[1:7], - c( - "[1] \"Table: Correlation Matrix (pearson-method)\" ", - "[2] \"\" ", - "[3] \"|Parameter | Petal.Width | Petal.Length | Sepal.Width |\"", - "[4] \"|:------------|:-----------:|:------------:|:-----------:|\"", - "[5] \"|Sepal.Length | 0.82*** | 0.87*** | -0.12 |\"", - "[6] \"|Sepal.Width | -0.37*** | -0.43*** | |\"", - "[7] \"|Petal.Length | 0.96*** | | |\"" - ) - ) + skip_if_not_or_load_if_installed("knitr") + expect_snapshot(display(summary(correlation(iris)))) }) # display and print method works - html ----------------------------- From f94ea3410b7d7d4362b712122096ca0bb4ea2cf4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 23:15:53 +0100 Subject: [PATCH 12/13] fix --- .../_snaps/display_print_dataframe.md | 20 +++++++++++++++++++ tests/testthat/_snaps/display_print_matrix.md | 16 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/testthat/_snaps/display_print_dataframe.md diff --git a/tests/testthat/_snaps/display_print_dataframe.md b/tests/testthat/_snaps/display_print_dataframe.md new file mode 100644 index 00000000..e5f35fd4 --- /dev/null +++ b/tests/testthat/_snaps/display_print_dataframe.md @@ -0,0 +1,20 @@ +# display and print method works - markdown + + Code + display(correlation(iris)) + Output + + + Table: Correlation Matrix (pearson-method) + + |Parameter1 | Parameter2 | r | 95% CI | t(148) | p | + |:------------|:------------:|:-----:|:--------------:|:------:|:---------:| + |Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 | + |Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** | + |Sepal.Length | Petal.Width | 0.82 | (0.76, 0.86) | 17.30 | < .001*** | + |Sepal.Width | Petal.Length | -0.43 | (-0.55, -0.29) | -5.77 | < .001*** | + |Sepal.Width | Petal.Width | -0.37 | (-0.50, -0.22) | -4.79 | < .001*** | + |Petal.Length | Petal.Width | 0.96 | (0.95, 0.97) | 43.39 | < .001*** | + p-value adjustment method: Holm (1979) + Observations: 150 + diff --git a/tests/testthat/_snaps/display_print_matrix.md b/tests/testthat/_snaps/display_print_matrix.md index 3f2e2085..0606b58f 100644 --- a/tests/testthat/_snaps/display_print_matrix.md +++ b/tests/testthat/_snaps/display_print_matrix.md @@ -1,3 +1,19 @@ +# display and print method works - markdown + + Code + display(summary(correlation(iris))) + Output + + + Table: Correlation Matrix (pearson-method) + + |Parameter | Petal.Width | Petal.Length | Sepal.Width | + |:------------|:-----------:|:------------:|:-----------:| + |Sepal.Length | 0.82*** | 0.87*** | -0.12 | + |Sepal.Width | -0.37*** | -0.43*** | | + |Petal.Length | 0.96*** | | | + p-value adjustment method: Holm (1979) + # as.matrix works Code From 4bdced8f63db45f58c5338a7958449b1a4155dcd Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 4 Jan 2025 23:17:29 +0100 Subject: [PATCH 13/13] update snapshot --- .../_snaps/display_print_dataframe.md | 20 +++++++++++++++++++ tests/testthat/_snaps/display_print_matrix.md | 16 +++++++++++++++ tests/testthat/test-display_print_dataframe.R | 1 + tests/testthat/test-display_print_matrix.R | 1 + 4 files changed, 38 insertions(+) diff --git a/tests/testthat/_snaps/display_print_dataframe.md b/tests/testthat/_snaps/display_print_dataframe.md index e5f35fd4..f53f57d6 100644 --- a/tests/testthat/_snaps/display_print_dataframe.md +++ b/tests/testthat/_snaps/display_print_dataframe.md @@ -18,3 +18,23 @@ p-value adjustment method: Holm (1979) Observations: 150 +--- + + Code + print_md(correlation(iris)) + Output + + + Table: Correlation Matrix (pearson-method) + + |Parameter1 | Parameter2 | r | 95% CI | t(148) | p | + |:------------|:------------:|:-----:|:--------------:|:------:|:---------:| + |Sepal.Length | Sepal.Width | -0.12 | (-0.27, 0.04) | -1.44 | 0.152 | + |Sepal.Length | Petal.Length | 0.87 | (0.83, 0.91) | 21.65 | < .001*** | + |Sepal.Length | Petal.Width | 0.82 | (0.76, 0.86) | 17.30 | < .001*** | + |Sepal.Width | Petal.Length | -0.43 | (-0.55, -0.29) | -5.77 | < .001*** | + |Sepal.Width | Petal.Width | -0.37 | (-0.50, -0.22) | -4.79 | < .001*** | + |Petal.Length | Petal.Width | 0.96 | (0.95, 0.97) | 43.39 | < .001*** | + p-value adjustment method: Holm (1979) + Observations: 150 + diff --git a/tests/testthat/_snaps/display_print_matrix.md b/tests/testthat/_snaps/display_print_matrix.md index 0606b58f..176b5138 100644 --- a/tests/testthat/_snaps/display_print_matrix.md +++ b/tests/testthat/_snaps/display_print_matrix.md @@ -5,6 +5,22 @@ Output + Table: Correlation Matrix (pearson-method) + + |Parameter | Petal.Width | Petal.Length | Sepal.Width | + |:------------|:-----------:|:------------:|:-----------:| + |Sepal.Length | 0.82*** | 0.87*** | -0.12 | + |Sepal.Width | -0.37*** | -0.43*** | | + |Petal.Length | 0.96*** | | | + p-value adjustment method: Holm (1979) + +--- + + Code + print_md(summary(correlation(iris))) + Output + + Table: Correlation Matrix (pearson-method) |Parameter | Petal.Width | Petal.Length | Sepal.Width | diff --git a/tests/testthat/test-display_print_dataframe.R b/tests/testthat/test-display_print_dataframe.R index e9234ad8..62465552 100644 --- a/tests/testthat/test-display_print_dataframe.R +++ b/tests/testthat/test-display_print_dataframe.R @@ -2,6 +2,7 @@ test_that("display and print method works - markdown", { skip_on_cran() skip_if_not_or_load_if_installed("knitr") expect_snapshot(display(correlation(iris))) + expect_snapshot(print_md(correlation(iris))) }) # display and print method works - HTML ----------------------------- diff --git a/tests/testthat/test-display_print_matrix.R b/tests/testthat/test-display_print_matrix.R index 812cf8ad..f7cf7add 100644 --- a/tests/testthat/test-display_print_matrix.R +++ b/tests/testthat/test-display_print_matrix.R @@ -4,6 +4,7 @@ test_that("display and print method works - markdown", { skip_on_cran() skip_if_not_or_load_if_installed("knitr") expect_snapshot(display(summary(correlation(iris)))) + expect_snapshot(print_md(summary(correlation(iris)))) }) # display and print method works - html -----------------------------