From 2b93ab92072dcac4ffa59e5d1730ff8fef2eceb7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Oct 2023 12:41:20 +0530 Subject: [PATCH 1/4] add template function with unit-test --- R/utils.R | 35 +++++++++++++++++++++++++++++++++++ man/card_template.Rd | 28 ++++++++++++++++++++++++++++ tests/testthat/test-utils.R | 26 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 man/card_template.Rd diff --git a/R/utils.R b/R/utils.R index c9b10403..1eb01034 100644 --- a/R/utils.R +++ b/R/utils.R @@ -295,3 +295,38 @@ global_knitr_details <- function() { collapse = "\n" ) } + +#' Template function to generate reporter card. +#' +#' This function generates a report card with a title, +#' an optional description, and the option to append the filter state list. +#' +#' @param title (`character(1)`) title of the card (unless overwritten by label) +#' @param label (`character(1)`) label provided by the user when adding the card +#' @param description (`character(1)`) optional additional description +#' @param with_filter (`logical(1)`) flag indicating to add filter state +#' @param filter_panel_api (`FilterPanelAPI`) object with API that allows the generation +#' of the filter state in the report +#' +#' @return (`TealReportCard`) populated with a title, description and filter state +#' +#' @keywords internal +card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { + checkmate::assert_string(title) + checkmate::assert_string(label) + checkmate::assert_string(description, null.ok = TRUE) + checkmate::assert_flag(with_filter) + checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") + + card <- teal::TealReportCard$new() + title <- if (label == "") title else label + card$set_name(title) + card$append_text(title, "header2") + if (!is.null(description)) { + card$append_text(description, "header3") + } + if (with_filter) { + card$append_fs(filter_panel_api$get_filter_state()) + } + card +} diff --git a/man/card_template.Rd b/man/card_template.Rd new file mode 100644 index 00000000..b555b0f3 --- /dev/null +++ b/man/card_template.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{card_template} +\alias{card_template} +\title{Template function to generate reporter card.} +\usage{ +card_template(title, label, description = NULL, with_filter, filter_panel_api) +} +\arguments{ +\item{title}{(\code{character(1)}) title of the card (unless overwritten by label)} + +\item{label}{(\code{character(1)}) label provided by the user when adding the card} + +\item{description}{(\code{character(1)}) optional additional description} + +\item{with_filter}{(\code{logical(1)}) flag indicating to add filter state} + +\item{filter_panel_api}{(\code{FilterPanelAPI}) object with API that allows the generation +of the filter state in the report} +} +\value{ +(\code{TealReportCard}) populated with a title, description and filter state +} +\description{ +This function generates a report card with a title, +an optional description, and the option to append the filter state list. +} +\keyword{internal} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b2c47f7b..25bd53ab 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -65,3 +65,29 @@ testthat::test_that("split_text_block - splits text block into blocks no longer result <- split_text_block(block_text, n) testthat::expect_equal(result, list(block_text)) }) + +testthat::test_that("card_template function returns TealReportCard object with appropriate content and labels", { + fd <- teal.slice::init_filtered_data(list(iris = list(dataset = iris))) + filter_panel_api <- teal.slice::FilterPanelAPI$new(fd) + + card <- shiny::isolate(card_template( + title = "Card title", + label = "Card label", + description = "Sample description", + with_filter = TRUE, + filter_panel_api = filter_panel_api + )) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card label") + testthat::expect_length(card$get_content(), 4) + + card <- shiny::isolate(card_template( + title = "Card title", + label = "", + with_filter = FALSE, + filter_panel_api = filter_panel_api + )) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card title") + testthat::expect_length(card$get_content(), 1) +}) From 3c0fed865f33b9dd06ed5ca1d2bbbeb3f8ce0d8b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Oct 2023 14:34:34 +0530 Subject: [PATCH 2/4] add card template function with unit-test. --- NAMESPACE | 1 + R/utils.R | 2 +- man/card_template.Rd | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 347f3e4f..776180f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(Reporter) export(add_card_button_srv) export(add_card_button_ui) export(as_yaml_auto) +export(card_template) export(download_report_button_srv) export(download_report_button_ui) export(reporter_previewer_srv) diff --git a/R/utils.R b/R/utils.R index 1eb01034..34b7d44f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -310,7 +310,7 @@ global_knitr_details <- function() { #' #' @return (`TealReportCard`) populated with a title, description and filter state #' -#' @keywords internal +#' @export card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { checkmate::assert_string(title) checkmate::assert_string(label) diff --git a/man/card_template.Rd b/man/card_template.Rd index b555b0f3..f4453255 100644 --- a/man/card_template.Rd +++ b/man/card_template.Rd @@ -25,4 +25,3 @@ of the filter state in the report} This function generates a report card with a title, an optional description, and the option to append the filter state list. } -\keyword{internal} From dd98080558f291ab3beed4d06bb8034bd20600f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Oct 2023 15:10:59 +0530 Subject: [PATCH 3/4] adding teal.slice for running unit-test --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4590d083..b1ae1226 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,6 +36,7 @@ Suggests: lattice (>= 0.18-4), png, rtables (>= 0.5.1), + teal.slice (>= 0.4.0), testthat (>= 3.0.4), tinytex VignetteBuilder: @@ -47,7 +48,8 @@ Config/Needs/verdepcheck: rstudio/bslib, mllg/checkmate, rstudio/rmarkdown, rstudio/shiny, dreamRs/shinyWidgets, yaml=vubiostat/r-yaml, r-lib/zip, davidgohel/flextable, rstudio/DT, yihui/formatR, tidyverse/ggplot2, deepayan/lattice, cran/png, - insightsengineering/rtables, r-lib/testthat, rstudio/tinytex + insightsengineering/rtables, insightsengineering/teal.slice, + r-lib/testthat, rstudio/tinytex Config/Needs/website: insightsengineering/nesttemplate Encoding: UTF-8 Language: en-US From b34f23765f2c7946f4b13986a5ea043b2baa94c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Oct 2023 15:26:55 +0530 Subject: [PATCH 4/4] adding teal in suggest --- DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b1ae1226..8865493e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,6 +36,7 @@ Suggests: lattice (>= 0.18-4), png, rtables (>= 0.5.1), + teal (>= 0.14.0), teal.slice (>= 0.4.0), testthat (>= 3.0.4), tinytex @@ -48,8 +49,8 @@ Config/Needs/verdepcheck: rstudio/bslib, mllg/checkmate, rstudio/rmarkdown, rstudio/shiny, dreamRs/shinyWidgets, yaml=vubiostat/r-yaml, r-lib/zip, davidgohel/flextable, rstudio/DT, yihui/formatR, tidyverse/ggplot2, deepayan/lattice, cran/png, - insightsengineering/rtables, insightsengineering/teal.slice, - r-lib/testthat, rstudio/tinytex + insightsengineering/rtables, insightsengineering/teal, + insightsengineering/teal.slice, r-lib/testthat, rstudio/tinytex Config/Needs/website: insightsengineering/nesttemplate Encoding: UTF-8 Language: en-US