diff --git a/tests/testthat/test-matrix_form.R b/tests/testthat/test-matrix_form.R index b5c2965a..126dec7c 100644 --- a/tests/testthat/test-matrix_form.R +++ b/tests/testthat/test-matrix_form.R @@ -1,10 +1,12 @@ test_that("matrix_form works with and without indentation", { + require("dplyr", quietly = TRUE) + skip_if_not_installed("dplyr") - iris_output <- dplyr::summarize(dplyr::group_by(iris, Species), - "all obs" = round(mean(Petal.Length), 2) - ) - iris_output <- dplyr::mutate(iris_output, "Petal.Length" = "Mean") + iris_output <- iris %>% + group_by(Species) %>% + summarize("all obs" = round(mean(Petal.Length), 2)) %>% + mutate("Petal.Length" = "Mean") mf <- basic_matrix_form(iris_output, indent_rownames = TRUE, diff --git a/tests/testthat/test-print.R b/tests/testthat/test-print.R index aa7064a8..56c15937 100644 --- a/tests/testthat/test-print.R +++ b/tests/testthat/test-print.R @@ -1,36 +1,33 @@ test_that("toString works with and without indentation", { + require("dplyr", quietly = TRUE) + skip_if_not_installed("dplyr") set.seed(1) - iris <- - dplyr::mutate(iris, my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE)) - iris_output <- - dplyr::summarize(dplyr::group_by(iris, Species, my_cols), - "mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop" - ) - iris_output_df <- as.data.frame(iris_output) - iris_output_df <- reshape( - iris_output_df, - timevar = "my_cols", - idvar = "Species", - direction = "wide", - v.names = "mean_petal_length" - ) - # identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>% - iris_output_df <- dplyr::rename( - iris_output_df, - A = `mean_petal_length.A`, - B = `mean_petal_length.B`, - C = `mean_petal_length.C` - ) - - iris_output_df <- dplyr::mutate(iris_output_df, "Petal.Length" = "Mean") + iris_output <- iris %>% + mutate(my_cols = sample(c("A", "B", "C"), nrow(iris), replace = TRUE)) %>% + group_by(Species, my_cols) %>% + summarize("mean_petal_length" = round(mean(Petal.Length), 1), .groups = "drop") %>% + as.data.frame() %>% + reshape( + timevar = "my_cols", + idvar = "Species", + direction = "wide", + v.names = "mean_petal_length" + ) %>% + # identical to tidyr::pivot_wider(names_from = my_cols, values_from = mean_petal_length) %>% + rename( + A = `mean_petal_length.A`, + B = `mean_petal_length.B`, + C = `mean_petal_length.C` + ) %>% + mutate("Petal.Length" = "Mean") - mf <- basic_matrix_form(iris_output_df, + mf <- basic_matrix_form(iris_output, indent_rownames = TRUE, split_labels = "Species", data_labels = "Petal.Length" ) - mf_no_indent <- basic_matrix_form(iris_output_df, + mf_no_indent <- basic_matrix_form(iris_output, indent_rownames = FALSE, split_labels = "Species", data_labels = "Petal.Length" )