From 9d031b8ea759857e27a2b65f4bf2b7fff33bfde7 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 12:32:50 -0600 Subject: [PATCH 1/3] Init testthat and vdiffr --- DESCRIPTION | 5 +++-- tests/testthat.R | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb984ef..2fea378 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,8 @@ Imports: sysfonts, tidyselect Suggests: - ggrepel, - testthat (>= 3.0.0) + ggrepel, + testthat (>= 3.0.0), + vdiffr Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/ diff --git a/tests/testthat.R b/tests/testthat.R index b475d7c..01d2cf1 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,12 @@ -# library(testthat) -# library(ojothemes) +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. # -# test_check("ojothemes") +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(ojothemes) + +test_check("ojothemes") From 8f4a04128338e71adf78c54d2bf0fc250c43ed11 Mon Sep 17 00:00:00 2001 From: Brancen Gregory Date: Tue, 12 Nov 2024 13:58:12 -0600 Subject: [PATCH 2/3] Add namespacing; replace argument name in element_line and element_rect due to deprecation; add basic vdiffr snapshot tests --- R/geoms.R | 2 +- R/theme_ojo.R | 10 +-- R/theme_okpi.R | 4 +- tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg | 0 .../_snaps/theme_okpi/demo-theme-okpi.svg | 88 +++++++++++++++++++ tests/testthat/test-ojo_gt.R | 18 ++++ tests/testthat/test-theme_okpi.R | 18 ++++ 7 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg create mode 100644 tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg create mode 100644 tests/testthat/test-ojo_gt.R create mode 100644 tests/testthat/test-theme_okpi.R diff --git a/R/geoms.R b/R/geoms.R index 4237235..70542e6 100644 --- a/R/geoms.R +++ b/R/geoms.R @@ -20,7 +20,7 @@ GeomColOJO <- ggplot2::ggproto( draw_panel = function(self, data, panel_params, coord, width = NULL) { # Hack to ensure that width is detected as a parameter - ggplot2::ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord) + ggplot2::ggproto_parent(ggplot2::GeomRect, self)$draw_panel(data, panel_params, coord) } ) diff --git a/R/theme_ojo.R b/R/theme_ojo.R index 2f36a9f..94d146f 100644 --- a/R/theme_ojo.R +++ b/R/theme_ojo.R @@ -16,12 +16,12 @@ theme_ojo_base <- function(base_size = 16, ggplot2::theme( line = ggplot2::element_line(colour = "#000000", - size = base_line_size, + linewidth = base_line_size, linetype = 1L, lineend = "butt"), rect = ggplot2::element_rect(fill = "#FFFFFF", colour = "#000000", - size = base_rect_size, + linewidth = base_rect_size, linetype = 1L), text = ggplot2::element_text(family = base_family, face = "plain", @@ -85,14 +85,14 @@ theme_ojo_base <- function(base_size = 16, axis.ticks = ggplot2::element_line(), axis.ticks.length = ggplot2::unit(4L, "pt"), axis.ticks.x = ggplot2::element_line(colour = NULL, - size = NULL, + linewidth = NULL, linetype = NULL, lineend = NULL), axis.ticks.y = ggplot2::element_blank(), axis.line = ggplot2::element_line(), axis.line.x = ggplot2::element_line(colour = NULL, - size = NULL, + linewidth = NULL, linetype = NULL, lineend = NULL), axis.line.y = ggplot2::element_blank(), @@ -142,7 +142,7 @@ theme_ojo_base <- function(base_size = 16, # strip attributes (Faceting) strip.background = ggplot2::element_rect(fill = "#dedddd", colour = NA, - size = 10L), + linewidth = 10L), strip.text = ggplot2::element_text(face = "bold", size = base_size * 9.5 / 8.5, margin = ggplot2::margin(t = 0L, r = 0L, b = 0L, l = 0L)), diff --git a/R/theme_okpi.R b/R/theme_okpi.R index 478e211..2c05b7c 100644 --- a/R/theme_okpi.R +++ b/R/theme_okpi.R @@ -16,12 +16,12 @@ theme_okpi_base <- function(base_size = 16, ggplot2::theme( line = ggplot2::element_line(colour = "#333333", - size = base_line_size, + linewidth = base_line_size, linetype = 1L, lineend = "butt"), rect = ggplot2::element_rect(fill = "#ffffff", colour = NA, - size = base_rect_size, + linewidth = base_rect_size, linetype = 1L), text = ggplot2::element_text(family = base_family, face = "plain", diff --git a/tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg b/tests/testthat/_snaps/ojo_gt/demo-ojo-gt.svg new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg b/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg new file mode 100644 index 0000000..f07c4b4 --- /dev/null +++ b/tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/test-ojo_gt.R b/tests/testthat/test-ojo_gt.R new file mode 100644 index 0000000..21d18a5 --- /dev/null +++ b/tests/testthat/test-ojo_gt.R @@ -0,0 +1,18 @@ +test_that("gt_okpi style is consistent", { + data <- tibble::tibble( + county = c("Tulsa", "Oklahoma"), + variable1 = c(95, 85), + variable2 = c(4.25, 3.12), + variable3 = c("factor1", "factor2") + ) + + vdiffr::expect_doppelganger("demo-ojo_gt", { + gt_okpi( + data, + title = "A demo table", + subtitle = "Towards beauty in our tables", + analyst_name = "Brancen Gregory", + source = ojo_source_text("oscn") + ) + }) +}) diff --git a/tests/testthat/test-theme_okpi.R b/tests/testthat/test-theme_okpi.R new file mode 100644 index 0000000..fd4ae8c --- /dev/null +++ b/tests/testthat/test-theme_okpi.R @@ -0,0 +1,18 @@ +test_that("theme_okpi is stable", { + data <- tibble::tibble( + county = c("Tulsa", "Oklahoma"), + variable1 = c(95, 85), + variable2 = c(4.25, 3.12), + variable3 = c("factor1", "factor2") + ) + + vdiffr::expect_doppelganger("demo-theme_okpi", { + ojo_set_theme() + + ggplot2::ggplot( + data, + ggplot2::aes(x = variable1, y = variable2, group = variable3) + ) + + geom_col() + }) +}) From 204aa27d3f3d7341128c00b3ee0f01b5f508ff4d Mon Sep 17 00:00:00 2001 From: andrewjbe <56839927+andrewjbe@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:56:06 -0600 Subject: [PATCH 3/3] adding tibble to suggests to get rid of a note on devtools::check() --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 2fea378..6a2e703 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: Suggests: ggrepel, testthat (>= 3.0.0), + tibble, vdiffr Config/testthat/edition: 3 URL: https://openjusticeok.github.io/ojothemes/