From 69fc4386da93a2579ec38edd05a1b7bf7dc6d456 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:10:29 +0100 Subject: [PATCH 1/2] 238 bring back internal examples (#239) Close #238 Examples moved to `dev/` folder during https://github.com/insightsengineering/teal.reporter/pull/209 were brough back to their places. We substituted `:::` usage, that is discouraged by CRAN, with `getFromNamespace()` function --- .Rbuildignore | 1 - R/Archiver.R | 52 ++++++++++ R/ContentBlock.R | 14 +++ R/FileBlock.R | 12 +++ R/NewpageBlock.R | 4 + R/PictureBlock.R | 30 ++++++ R/RcodeBlock.R | 29 ++++++ R/Renderer.R | 82 ++++++++++++++++ R/ReportCard.R | 5 +- R/TableBlock.R | 5 + R/TextBlock.R | 29 ++++++ R/yaml_utils.R | 29 ++++++ dev/internal_examples.R | 196 -------------------------------------- man/Archiver.Rd | 18 ++++ man/ContentBlock.Rd | 60 ++++++++++++ man/FileArchiver.Rd | 34 +++++++ man/FileBlock.Rd | 46 +++++++++ man/JSONArchiver.Rd | 108 +++++++++++++++++++++ man/NewpageBlock.Rd | 20 ++++ man/RcodeBlock.Rd | 120 +++++++++++++++++++++++ man/Renderer.Rd | 206 ++++++++++++++++++++++++++++++++++++++++ man/ReportCard.Rd | 18 ++++ man/TableBlock.Rd | 22 +++++ man/TextBlock.Rd | 120 +++++++++++++++++++++++ man/conv_str_logi.Rd | 11 +++ man/md_header.Rd | 11 +++ man/yaml_quoted.Rd | 10 ++ 27 files changed, 1093 insertions(+), 199 deletions(-) delete mode 100644 dev/internal_examples.R diff --git a/.Rbuildignore b/.Rbuildignore index f56fe510..e4a572d6 100755 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,7 +1,6 @@ ^assets$ ^venv$ LICENSE -dev/internal_examples.R ^.*\.Rproj$ ^Jenkinsfile$ ^Makefile$ diff --git a/R/Archiver.R b/R/Archiver.R index 883e579f..bbc664d1 100644 --- a/R/Archiver.R +++ b/R/Archiver.R @@ -6,6 +6,9 @@ Archiver <- R6::R6Class( # nolint: object_name_linter. #' @description Returns an `Archiver` object. #' #' @return an `Archiver` object + #' @examples + #' Archiver <- getFromNamespace("Archiver", "teal.reporter") + #' Archiver$new() initialize = function() { invisible(self) }, @@ -36,6 +39,9 @@ FileArchiver <- R6::R6Class( # nolint: object_name_linter. #' @description Returns a `FileArchiver` object. #' #' @return a `FileArchiver` object + #' @examples + #' FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") + #' FileArchiver$new() initialize = function() { tmp_dir <- tempdir() output_dir <- file.path(tmp_dir, sprintf("archive_%s", gsub("[.]", "", format(Sys.time(), "%Y%m%d%H%M%OS4")))) @@ -50,6 +56,9 @@ FileArchiver <- R6::R6Class( # nolint: object_name_linter. #' @description get `output_dir` field #' #' @return `character` a `output_dir` field path. + #' @examples + #' FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") + #' FileArchiver$new()$get_output_dir() get_output_dir = function() { private$output_dir } @@ -70,6 +79,24 @@ JSONArchiver <- R6::R6Class( # nolint: object_name_linter. #' @param reporter `Reporter` instance. #' #' @return invisibly self + #' @examples + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card1 <- ReportCard$new() + #' + #' card1$append_text("Header 2 text", "header2") + #' card1$append_text("A paragraph of default text", "header2") + #' card1$append_plot( + #' ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() + #' ) + #' + #' Reporter <- getFromNamespace("Reporter", "teal.reporter") + #' reporter <- Reporter$new() + #' reporter$append_cards(list(card1)) + #' + #' JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") + #' archiver <- JSONArchiver$new() + #' archiver$write(reporter) + #' archiver$get_output_dir() write = function(reporter) { checkmate::assert_class(reporter, "Reporter") unlink(list.files(private$output_dir, recursive = TRUE, full.names = TRUE)) @@ -81,6 +108,31 @@ JSONArchiver <- R6::R6Class( # nolint: object_name_linter. #' @param path `character(1)` a path to the directory with all proper files. #' #' @return `Reporter` instance. + #' @examples + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card1 <- ReportCard$new() + #' + #' card1$append_text("Header 2 text", "header2") + #' card1$append_text("A paragraph of default text", "header2") + #' card1$append_plot( + #' ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() + #' ) + #' + #' Reporter <- getFromNamespace("Reporter", "teal.reporter") + #' reporter <- Reporter$new() + #' reporter$append_cards(list(card1)) + #' + #' JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") + #' archiver <- JSONArchiver$new() + #' archiver$write(reporter) + #' archiver$get_output_dir() + #' + #' archiver$read()$get_cards()[[1]]$get_content() + #' Reporter <- getFromNamespace("Reporter", "teal.reporter") + #' blocks <- Reporter$new() + #' blocks <- blocks$from_reporter(archiver$read())$get_blocks() + #' Renderer <- getFromNamespace("Renderer", "teal.reporter") + #' doc <- Renderer$new()$render(blocks) read = function(path = NULL) { checkmate::assert( checkmate::check_null(path), diff --git a/R/ContentBlock.R b/R/ContentBlock.R index becedfd9..f10074a9 100644 --- a/R/ContentBlock.R +++ b/R/ContentBlock.R @@ -8,6 +8,10 @@ ContentBlock <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `ContentBlock` object with no content and the default style. #' #' @return `ContentBlock` + #' @examples + #' ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") + #' ContentBlock$new() + #' initialize = function() { private$content <- character(0) invisible(self) @@ -17,6 +21,11 @@ ContentBlock <- R6::R6Class( # nolint: object_name_linter. #' @param content (`character(0)` or `character(1)`) a string literal or a file path assigned to this `ContentBlock` #' #' @return invisibly self + #' @examples + #' ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") + #' block <- ContentBlock$new() + #' block$set_content("Base64 encoded picture") + #' set_content = function(content) { checkmate::assert_character(content, min.len = 0, max.len = 1) private$content <- content @@ -25,6 +34,11 @@ ContentBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the absolute path to content of this `ContentBlock` #' #' @return `character` content of this `ContentBlock` + #' @examples + #' ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") + #' block <- ContentBlock$new() + #' block$get_content() + #' get_content = function() { private$content }, diff --git a/R/FileBlock.R b/R/FileBlock.R index c0613fb8..39955e6b 100644 --- a/R/FileBlock.R +++ b/R/FileBlock.R @@ -17,6 +17,13 @@ FileBlock <- R6::R6Class( # nolint: object_name_linter. #' @param output_dir `character` with a path to the directory where a file will be copied. #' #' @return invisibly self + #' @examples + #' FileBlock <- getFromNamespace("FileBlock", "teal.reporter") + #' block <- FileBlock$new() + #' file_path <- tempfile(fileext = ".png") + #' saveRDS(iris, file_path) + #' block$from_list(list(basename = basename(file_path)), dirname(file_path)) + #' from_list = function(x, output_dir) { checkmate::assert_list(x) checkmate::assert_names(names(x), must.include = "basename") @@ -33,6 +40,11 @@ FileBlock <- R6::R6Class( # nolint: object_name_linter. #' @param output_dir `character` with a path to the directory where a file will be copied. #' #' @return `named list` with a `basename` of the file. + #' @examples + #' FileBlock <- getFromNamespace("FileBlock", "teal.reporter") + #' block <- FileBlock$new() + #' block$to_list(tempdir()) + #' to_list = function(output_dir) { base_name <- basename(super$get_content()) file.copy(super$get_content(), file.path(output_dir, base_name)) diff --git a/R/NewpageBlock.R b/R/NewpageBlock.R index b08613cc..2438fd88 100644 --- a/R/NewpageBlock.R +++ b/R/NewpageBlock.R @@ -9,6 +9,10 @@ NewpageBlock <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `NewpageBlock` object with no content and the default style. #' #' @return `NewpageBlock` + #' @examples + #' NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") + #' block <- NewpageBlock$new() + #' initialize = function() { super$set_content("\n\\newpage\n") invisible(self) diff --git a/R/PictureBlock.R b/R/PictureBlock.R index 2e779587..42c4eaf9 100644 --- a/R/PictureBlock.R +++ b/R/PictureBlock.R @@ -23,6 +23,18 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param content (`ggplot`, `grob`, `trellis`) a picture in this `PictureBlock` #' #' @return invisibly self + #' @examples + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$set_content(ggplot2::ggplot(iris)) + #' + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$set_content(lattice::bwplot(1)) + #' + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$set_content(ggplot2::ggplotGrob(ggplot2::ggplot(iris))) set_content = function(content) { checkmate::assert_multi_class(content, private$supported_plots) path <- tempfile(fileext = ".png") @@ -51,6 +63,11 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param title (`character(1)`) a string assigned to this `PictureBlock` #' #' @return invisibly self + #' @examples + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$set_title("Title") + #' set_title = function(title) { checkmate::assert_string(title) private$title <- title @@ -59,6 +76,10 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the title of this `PictureBlock` #' #' @return the content of this `PictureBlock` + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$get_title() + #' get_title = function() { private$title }, @@ -67,6 +88,11 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param dim `numeric` figure dimensions (width and height) in pixels, length 2. #' #' @return `self` + #' @examples + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$set_dim(c(800, 600)) + #' set_dim = function(dim) { checkmate::assert_numeric(dim, len = 2) private$dim <- dim @@ -75,6 +101,10 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the dimensions of this `PictureBlock` #' #' @return `numeric` the array of 2 numeric values representing width and height in pixels. + #' @examples + #' PictureBlock <- getFromNamespace("PictureBlock", "teal.reporter") + #' block <- PictureBlock$new() + #' block$get_dim() get_dim = function() { private$dim } diff --git a/R/RcodeBlock.R b/R/RcodeBlock.R index 2f7d67f0..939d378d 100644 --- a/R/RcodeBlock.R +++ b/R/RcodeBlock.R @@ -12,6 +12,10 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @param ... any `rmarkdown` R chunk parameter and it value. #' #' @return `RcodeBlock` + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' initialize = function(content = character(0), ...) { super$set_content(content) self$set_params(list(...)) @@ -24,6 +28,11 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @param params (`list`) any `rmarkdown` R chunk parameter and its value. #' #' @return invisibly self + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' block$set_params(list(echo = TRUE)) + #' set_params = function(params) { checkmate::assert_list(params, names = "named") checkmate::assert_subset(names(params), self$get_available_params()) @@ -33,12 +42,22 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the parameters of this `RcodeBlock`. #' #' @return `character` the parameters of this `RcodeBlock` + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' block$get_params() + #' get_params = function() { private$params }, #' @description Returns an array of parameters available to this `RcodeBlock`. #' #' @return a `character` array of parameters + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' block$get_available_params() + #' get_available_params = function() { names(knitr::opts_chunk$get()) }, @@ -48,6 +67,11 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' Use the `get_available_params` method to get all possible parameters. #' #' @return invisibly self + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' block$from_list(list(text = "sth", params = list())) + #' from_list = function(x) { checkmate::assert_list(x) checkmate::assert_names(names(x), must.include = c("text", "params")) @@ -58,6 +82,11 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Convert the `RcodeBlock` to a list. #' #' @return `named list` with a text and `params`. + #' @examples + #' RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") + #' block <- RcodeBlock$new() + #' block$to_list() + #' to_list = function() { list(text = self$get_content(), params = self$get_params()) } diff --git a/R/Renderer.R b/R/Renderer.R index 8134433f..cfa1877c 100644 --- a/R/Renderer.R +++ b/R/Renderer.R @@ -8,6 +8,10 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `Renderer` object. #' #' @return `Renderer` object. + #' @examples + #' Renderer <- getFromNamespace("Renderer", "teal.reporter") + #' Renderer$new() + #' initialize = function() { tmp_dir <- tempdir() output_dir <- file.path(tmp_dir, sprintf("report_%s", gsub("[.]", "", format(Sys.time(), "%Y%m%d%H%M%OS4")))) @@ -28,6 +32,44 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @details `r global_knitr_details()` #' #' @return `character` a `Rmd` text (`yaml` header + body), ready to be rendered. + #' @examples + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card1 <- ReportCard$new() + #' + #' card1$append_text("Header 2 text", "header2") + #' card1$append_text("A paragraph of default text") + #' card1$append_plot( + #' ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() + #' ) + #' + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card2 <- ReportCard$new() + #' + #' card2$append_text("Header 2 text", "header2") + #' card2$append_text("A paragraph of default text", "header2") + #' lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) + #' table_res2 <- rtables::build_table(lyt, airquality) + #' card2$append_table(table_res2) + #' card2$append_table(iris) + #' card2$append_rcode("2+2", echo = FALSE) + #' + #' Reporter <- getFromNamespace("Reporter", "teal.reporter") + #' reporter <- Reporter$new() + #' reporter$append_cards(list(card1, card2)) + #' + #' yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") + #' yaml_l <- list( + #' author = yaml_quoted("NEST"), + #' title = yaml_quoted("Report"), + #' date = yaml_quoted("07/04/2019"), + #' output = list(html_document = list(toc = FALSE)) + #' ) + #' + #' md_header <- getFromNamespace("md_header", "teal.reporter") + #' yaml_header <- md_header(yaml::as.yaml(yaml_l)) + #' Renderer <- getFromNamespace("Renderer", "teal.reporter") + #' result_path <- Renderer$new()$renderRmd(reporter$get_blocks(), yaml_header) + #' renderRmd = function(blocks, yaml_header, global_knitr = getOption("teal.reporter.global_knitr")) { checkmate::assert_list(blocks, c("TextBlock", "PictureBlock", "NewpageBlock", "TableBlock", "RcodeBlock")) checkmate::assert_subset(names(global_knitr), names(knitr::opts_chunk$get())) @@ -89,6 +131,42 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @details `r global_knitr_details()` #' #' @return `character` path to the output + #' @examples + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card1 <- ReportCard$new() + #' + #' card1$append_text("Header 2 text", "header2") + #' card1$append_text("A paragraph of default text") + #' card1$append_plot( + #' ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() + #' ) + #' + #' ReportCard <- getFromNamespace("ReportCard", "teal.reporter") + #' card2 <- ReportCard$new() + #' + #' card2$append_text("Header 2 text", "header2") + #' card2$append_text("A paragraph of default text", "header2") + #' lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) + #' table_res2 <- rtables::build_table(lyt, airquality) + #' card2$append_table(table_res2) + #' card2$append_table(iris) + #' card2$append_rcode("2+2", echo = FALSE) + #' Reporter <- getFromNamespace("Reporter", "teal.reporter")$new() + #' Reporter$append_cards(list(card1, card2)) + #' + #' yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") + #' yaml_l <- list( + #' author = yaml_quoted("NEST"), + #' title = yaml_quoted("Report"), + #' date = yaml_quoted("07/04/2019"), + #' output = list(html_document = list(toc = FALSE)) + #' ) + #' + #' md_header <- getFromNamespace("md_header", "teal.reporter") + #' yaml_header <- md_header(yaml::as.yaml(yaml_l)) + #' Renderer <- getFromNamespace("Renderer", "teal.reporter") + #' result_path <- Renderer$new()$render(Reporter$get_blocks(), yaml_header) + #' render = function(blocks, yaml_header, global_knitr = getOption("teal.reporter.global_knitr"), ...) { args <- list(...) input_path <- self$renderRmd(blocks, yaml_header, global_knitr) @@ -106,6 +184,10 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @description get `output_dir` field #' #' @return `character` a `output_dir` field path. + #' @examples + #' Renderer <- getFromNamespace("Renderer", "teal.reporter")$new() + #' Renderer$get_output_dir() + #' get_output_dir = function() { private$output_dir } diff --git a/R/ReportCard.R b/R/ReportCard.R index 49352409..0a527a9b 100644 --- a/R/ReportCard.R +++ b/R/ReportCard.R @@ -76,10 +76,11 @@ ReportCard <- R6::R6Class( # nolint: object_name_linter. #' #' @param content (`ContentBlock`) #' @return invisibly self + #' @examples + #' NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") + #' card <- ReportCard$new()$append_content(NewpageBlock$new()) #' append_content = function(content) { - # example: # nolint - # card <- ReportCard$new()$append_content(teal.reporter:::NewpageBlock$new()) # nolint checkmate::assert_class(content, "ContentBlock") private$content <- append(private$content, content) invisible(self) diff --git a/R/TableBlock.R b/R/TableBlock.R index 98060ae3..ffcfe8e5 100644 --- a/R/TableBlock.R +++ b/R/TableBlock.R @@ -24,6 +24,11 @@ TableBlock <- R6::R6Class( # nolint: object_name_linter. #' this `TableBlock` #' #' @return invisibly self + #' @examples + #' TableBlock <- getFromNamespace("TableBlock", "teal.reporter") + #' block <- TableBlock$new() + #' block$set_content(iris) + #' set_content = function(content) { checkmate::assert_multi_class(content, private$supported_tables) content <- to_flextable(content) diff --git a/R/TextBlock.R b/R/TextBlock.R index 1a053038..1e5b2f43 100644 --- a/R/TextBlock.R +++ b/R/TextBlock.R @@ -12,6 +12,10 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @param style (`character(1)`) one of: `"default"`, `"header2"`, `"header3"` `"verbatim"` #' #' @return `TextBlock` + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' initialize = function(content = character(0), style = private$styles[1]) { super$set_content(content) self$set_style(style) @@ -24,6 +28,11 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @param style (`character(1)`) one of: `"default"`, `"header2"`, `"header3"` `"verbatim"` #' #' @return invisibly self + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' block$set_style("header2") + #' set_style = function(style) { private$style <- match.arg(style, private$styles) invisible(self) @@ -31,12 +40,22 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the style of this `TextBlock`. #' #' @return `character(1)` the style of this `TextBlock` + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' block$get_style() + #' get_style = function() { private$style }, #' @description Returns an array of styles available to this `TextBlock`. #' #' @return a `character` array of styles + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' block$get_available_styles() + #' get_available_styles = function() { private$styles }, @@ -46,6 +65,11 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' Use the `get_available_styles` method to get all possible styles. #' #' @return invisibly self + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' block$from_list(list(text = "sth", style = "default")) + #' from_list = function(x) { checkmate::assert_list(x) checkmate::assert_names(names(x), must.include = c("text", "style")) @@ -56,6 +80,11 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Convert the `TextBlock` to a list. #' #' @return `named list` with a text and style. + #' @examples + #' TextBlock <- getFromNamespace("TextBlock", "teal.reporter") + #' block <- TextBlock$new() + #' block$to_list() + #' to_list = function() { list(text = self$get_content(), style = self$get_style()) } diff --git a/R/yaml_utils.R b/R/yaml_utils.R index de19c87c..34804c83 100644 --- a/R/yaml_utils.R +++ b/R/yaml_utils.R @@ -2,6 +2,15 @@ #' @description add quoted attribute for `yaml` package #' @param x `character` #' @keywords internal +#' @examples +#' yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +#' yaml <- list( +#' author = yaml_quoted("NEST"), +#' title = yaml_quoted("Report"), +#' date = yaml_quoted("07/04/2019"), +#' output = list(pdf_document = list(keep_tex = TRUE)) +#' ) +#' yaml::as.yaml(yaml) yaml_quoted <- function(x) { attr(x, "quoted") <- TRUE x @@ -11,6 +20,16 @@ yaml_quoted <- function(x) { #' @description wrap a `yaml` string to the `markdown` header. #' @param x `character` `yaml` formatted string. #' @keywords internal +#' @examples +#' yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +#' yaml <- list( +#' author = yaml_quoted("NEST"), +#' title = yaml_quoted("Report"), +#' date = yaml_quoted("07/04/2019"), +#' output = list(pdf_document = list(keep_tex = TRUE)) +#' ) +#' md_header <- getFromNamespace("md_header", "teal.reporter") +#' md_header(yaml::as.yaml(yaml)) md_header <- function(x) { paste0("---\n", x, "---\n") } @@ -24,6 +43,16 @@ md_header <- function(x) { #' @param silent `logical` if to suppress the messages and warnings. #' @return `input` argument or the appropriate `logical` value. #' @keywords internal +#' @examples +#' +#' conv_str_logi <- getFromNamespace("conv_str_logi", "teal.reporter") +#' conv_str_logi("TRUE") +#' conv_str_logi("True") +#' +#' conv_str_logi("off") +#' conv_str_logi("n") +#' +#' conv_str_logi("sth") conv_str_logi <- function(input, name = "", pos_logi = c("TRUE", "true", "True", "yes", "y", "Y", "on"), diff --git a/dev/internal_examples.R b/dev/internal_examples.R deleted file mode 100644 index 3b547144..00000000 --- a/dev/internal_examples.R +++ /dev/null @@ -1,196 +0,0 @@ -# Archiver.R ---- - -## Archiver ---- - -archiver <- teal.reporter:::Archiver$new() - -## FileArchiver ---- - -archiver <- teal.reporter:::FileArchiver$new() -archiver$get_output_dir() - -## JSONArchiver ---- - -card1 <- teal.reporter::ReportCard$new() - -card1$append_text("Header 2 text", "header2") -card1$append_text("A paragraph of default text", "header2") -card1$append_plot( - ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + - ggplot2::geom_histogram() -) - -reporter <- teal.reporter::Reporter$new() -reporter$append_cards(list(card1)) - -archiver <- teal.reporter:::JSONArchiver$new() -archiver$write(reporter) -archiver$get_output_dir() - -archiver$read()$get_cards()[[1]]$get_content() -blocks <- teal.reporter::Reporter$new()$from_reporter(archiver$read())$get_blocks() -doc <- teal.reporter:::Renderer$new()$render(blocks) - -# ContentBlock.R ---- - -block <- teal.reporter:::ContentBlock$new() -block$set_content("Base64 encoded picture") -block$get_content() - -# FileBlock.R ---- - -block <- teal.reporter:::FileBlock$new() -file_path <- tempfile(fileext = ".png") -saveRDS(iris, file_path) -block$from_list(list(basename = basename(file_path)), dirname(file_path)) - -block <- teal.reporter:::FileBlock$new() -block$to_list(tempdir()) - -# NewpageBlock.R ---- - -block <- teal.reporter:::NewpageBlock$new() - -# PictureBlock.R ---- - -block <- teal.reporter:::PictureBlock$new() -block$set_content(ggplot2::ggplot(iris)) - -block <- teal.reporter:::PictureBlock$new() -block$set_content(lattice::bwplot(1)) - -block <- teal.reporter:::PictureBlock$new() -block$set_content(ggplot2::ggplotGrob(ggplot2::ggplot(iris))) - -block <- teal.reporter:::PictureBlock$new() -block$set_title("Title") -block$get_title() - -block <- teal.reporter:::PictureBlock$new() -block$set_dim(c(800, 600)) -block$get_dim() - -# RcodeBlock.R ---- - -block <- teal.reporter:::RcodeBlock$new() -block$set_params(list(echo = TRUE)) -block$get_params() -block$get_available_params() -block$from_list(list(text = "sth", params = list())) -block$to_list() - -# Renderer.R ---- - -renderer <- teal.reporter:::Renderer$new() -renderer$get_output_dir() - -## renderRmd ---- -card1 <- teal.reporter::ReportCard$new() - -card1$append_text("Header 2 text", "header2") -card1$append_text("A paragraph of default text") -card1$append_plot( - ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + - ggplot2::geom_histogram() -) - -card2 <- teal.reporter::ReportCard$new() - -card2$append_text("Header 2 text", "header2") -card2$append_text("A paragraph of default text", "header2") -lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) -table_res2 <- rtables::build_table(lyt, airquality) -card2$append_table(table_res2) -card2$append_table(iris) -card2$append_rcode("2+2", echo = FALSE) - -reporter <- teal.reporter::Reporter$new() -reporter$append_cards(list(card1, card2)) - -yaml_l <- list( - author = teal.reporter:::yaml_quoted("NEST"), - title = teal.reporter:::yaml_quoted("Report"), - date = teal.reporter:::yaml_quoted("07/04/2019"), - output = list(html_document = list(toc = FALSE)) -) - -yaml_header <- teal.reporter:::md_header(yaml::as.yaml(yaml_l)) -result_path <- teal.reporter:::Renderer$new()$renderRmd(reporter$get_blocks(), yaml_header) - -## render ---- - -card1 <- teal.reporter::ReportCard$new() -card1$append_text("Header 2 text", "header2") -card1$append_text("A paragraph of default text") -card1$append_plot( - ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + - ggplot2::geom_histogram() -) - -card2 <- teal.reporter::ReportCard$new() -card2$append_text("Header 2 text", "header2") -card2$append_text("A paragraph of default text", "header2") -lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) -table_res2 <- rtables::build_table(lyt, airquality) -card2$append_table(table_res2) -card2$append_table(iris) -card2$append_rcode("2+2", echo = FALSE) - -reporter <- teal.reporter::Reporter$new() -reporter$append_cards(list(card1, card2)) - -yaml_l <- list( - author = teal.reporter:::yaml_quoted("NEST"), - title = teal.reporter:::yaml_quoted("Report"), - date = teal.reporter:::yaml_quoted("07/04/2019"), - output = list(html_document = list(toc = FALSE)) -) - -yaml_header <- teal.reporter:::md_header(yaml::as.yaml(yaml_l)) -result_path <- teal.reporter:::Renderer$new()$render(reporter$get_blocks(), yaml_header) - -# TableBlock.R ---- - -block <- teal.reporter:::TableBlock$new() -block$set_content(iris) - -# TextBlock.R ---- - -block <- teal.reporter:::TextBlock$new() -block$set_style("header2") -block$get_style() -block$get_available_styles() -block$from_list(list(text = "sth", style = "default")) -block$to_list() - -# yaml_utils.R ---- - -## yaml_quoted ---- - -yaml <- list( - author = teal.reporter:::yaml_quoted("NEST"), - title = teal.reporter:::yaml_quoted("Report"), - date = teal.reporter:::yaml_quoted("07/04/2019"), - output = list(pdf_document = list(keep_tex = TRUE)) -) -yaml::as.yaml(yaml) - -## md_header ---- - -yaml <- list( - author = teal.reporter:::yaml_quoted("NEST"), - title = teal.reporter:::yaml_quoted("Report"), - date = teal.reporter:::yaml_quoted("07/04/2019"), - output = list(pdf_document = list(keep_tex = TRUE)) -) -teal.reporter:::md_header(yaml::as.yaml(yaml)) - -## conv_str_logi ---- - -teal.reporter:::conv_str_logi("TRUE") -teal.reporter:::conv_str_logi("True") - -teal.reporter:::conv_str_logi("off") -teal.reporter:::conv_str_logi("n") - -teal.reporter:::conv_str_logi("sth") diff --git a/man/Archiver.Rd b/man/Archiver.Rd index 4632ad69..3bd557d7 100644 --- a/man/Archiver.Rd +++ b/man/Archiver.Rd @@ -8,6 +8,15 @@ \code{Archiver} } +\examples{ + +## ------------------------------------------------ +## Method `Archiver$new` +## ------------------------------------------------ + +Archiver <- getFromNamespace("Archiver", "teal.reporter") +Archiver$new() +} \keyword{internal} \section{Methods}{ \subsection{Public methods}{ @@ -31,6 +40,15 @@ Returns an \code{Archiver} object. \subsection{Returns}{ an \code{Archiver} object } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{Archiver <- getFromNamespace("Archiver", "teal.reporter") +Archiver$new() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/ContentBlock.Rd b/man/ContentBlock.Rd index 9a48b63d..8d553e5a 100644 --- a/man/ContentBlock.Rd +++ b/man/ContentBlock.Rd @@ -7,6 +7,34 @@ \code{ContentBlock} \code{ContentBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `ContentBlock$new` +## ------------------------------------------------ + +ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +ContentBlock$new() + + +## ------------------------------------------------ +## Method `ContentBlock$set_content` +## ------------------------------------------------ + +ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +block <- ContentBlock$new() +block$set_content("Base64 encoded picture") + + +## ------------------------------------------------ +## Method `ContentBlock$get_content` +## ------------------------------------------------ + +ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +block <- ContentBlock$new() +block$get_content() + } \keyword{internal} \section{Methods}{ @@ -36,6 +64,16 @@ Returns a \code{ContentBlock} object with no content and the default style. \subsection{Returns}{ \code{ContentBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +ContentBlock$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -56,6 +94,17 @@ Sets content of this \code{ContentBlock}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +block <- ContentBlock$new() +block$set_content("Base64 encoded picture") + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -69,6 +118,17 @@ Returns the absolute path to content of this \code{ContentBlock} \subsection{Returns}{ \code{character} content of this \code{ContentBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ContentBlock <- getFromNamespace("ContentBlock", "teal.reporter") +block <- ContentBlock$new() +block$get_content() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/FileArchiver.Rd b/man/FileArchiver.Rd index 22a0aa53..275db960 100644 --- a/man/FileArchiver.Rd +++ b/man/FileArchiver.Rd @@ -8,6 +8,22 @@ \code{RDSArchiver} } +\examples{ + +## ------------------------------------------------ +## Method `FileArchiver$new` +## ------------------------------------------------ + +FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") +FileArchiver$new() + +## ------------------------------------------------ +## Method `FileArchiver$get_output_dir` +## ------------------------------------------------ + +FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") +FileArchiver$new()$get_output_dir() +} \keyword{internal} \section{Super class}{ \code{\link[teal.reporter:Archiver]{teal.reporter::Archiver}} -> \code{FileArchiver} @@ -41,6 +57,15 @@ Returns a \code{FileArchiver} object. \subsection{Returns}{ a \code{FileArchiver} object } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") +FileArchiver$new() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -64,6 +89,15 @@ get \code{output_dir} field \subsection{Returns}{ \code{character} a \code{output_dir} field path. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{FileArchiver <- getFromNamespace("FileArchiver", "teal.reporter") +FileArchiver$new()$get_output_dir() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/FileBlock.Rd b/man/FileBlock.Rd index 8ef3f115..4c5c6215 100644 --- a/man/FileBlock.Rd +++ b/man/FileBlock.Rd @@ -7,6 +7,28 @@ \code{FileBlock} \code{FileBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `FileBlock$from_list` +## ------------------------------------------------ + +FileBlock <- getFromNamespace("FileBlock", "teal.reporter") +block <- FileBlock$new() +file_path <- tempfile(fileext = ".png") +saveRDS(iris, file_path) +block$from_list(list(basename = basename(file_path)), dirname(file_path)) + + +## ------------------------------------------------ +## Method `FileBlock$to_list` +## ------------------------------------------------ + +FileBlock <- getFromNamespace("FileBlock", "teal.reporter") +block <- FileBlock$new() +block$to_list(tempdir()) + } \keyword{internal} \section{Super class}{ @@ -66,6 +88,19 @@ The list should contain one named field, \code{"basename"}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{FileBlock <- getFromNamespace("FileBlock", "teal.reporter") +block <- FileBlock$new() +file_path <- tempfile(fileext = ".png") +saveRDS(iris, file_path) +block$from_list(list(basename = basename(file_path)), dirname(file_path)) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -86,6 +121,17 @@ Convert the \code{FileBlock} to a list. \subsection{Returns}{ \verb{named list} with a \code{basename} of the file. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{FileBlock <- getFromNamespace("FileBlock", "teal.reporter") +block <- FileBlock$new() +block$to_list(tempdir()) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/JSONArchiver.Rd b/man/JSONArchiver.Rd index e1d0bdde..b897b2de 100644 --- a/man/JSONArchiver.Rd +++ b/man/JSONArchiver.Rd @@ -8,6 +8,59 @@ \code{JSONArchiver} } +\examples{ + +## ------------------------------------------------ +## Method `JSONArchiver$write` +## ------------------------------------------------ + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text", "header2") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1)) + +JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") +archiver <- JSONArchiver$new() +archiver$write(reporter) +archiver$get_output_dir() + +## ------------------------------------------------ +## Method `JSONArchiver$read` +## ------------------------------------------------ + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text", "header2") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1)) + +JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") +archiver <- JSONArchiver$new() +archiver$write(reporter) +archiver$get_output_dir() + +archiver$read()$get_cards()[[1]]$get_content() +Reporter <- getFromNamespace("Reporter", "teal.reporter") +blocks <- Reporter$new() +blocks <- blocks$from_reporter(archiver$read())$get_blocks() +Renderer <- getFromNamespace("Renderer", "teal.reporter") +doc <- Renderer$new()$render(blocks) +} \keyword{internal} \section{Super classes}{ \code{\link[teal.reporter:Archiver]{teal.reporter::Archiver}} -> \code{\link[teal.reporter:FileArchiver]{teal.reporter::FileArchiver}} -> \code{JSONArchiver} @@ -48,6 +101,30 @@ write a \code{Reporter} instance in to this \code{JSONArchiver} object. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text", "header2") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1)) + +JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") +archiver <- JSONArchiver$new() +archiver$write(reporter) +archiver$get_output_dir() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -68,6 +145,37 @@ read a \code{Reporter} instance from a directory with \code{JSONArchiver}. \subsection{Returns}{ \code{Reporter} instance. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text", "header2") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1)) + +JSONArchiver <- getFromNamespace("JSONArchiver", "teal.reporter") +archiver <- JSONArchiver$new() +archiver$write(reporter) +archiver$get_output_dir() + +archiver$read()$get_cards()[[1]]$get_content() +Reporter <- getFromNamespace("Reporter", "teal.reporter") +blocks <- Reporter$new() +blocks <- blocks$from_reporter(archiver$read())$get_blocks() +Renderer <- getFromNamespace("Renderer", "teal.reporter") +doc <- Renderer$new()$render(blocks) +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/NewpageBlock.Rd b/man/NewpageBlock.Rd index 9f9020e9..5e4edc4a 100644 --- a/man/NewpageBlock.Rd +++ b/man/NewpageBlock.Rd @@ -7,6 +7,16 @@ \code{NewpageBlock} \code{NewpageBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `NewpageBlock$new` +## ------------------------------------------------ + +NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") +block <- NewpageBlock$new() + } \keyword{internal} \section{Super class}{ @@ -45,6 +55,16 @@ Returns a \code{NewpageBlock} object with no content and the default style. \subsection{Returns}{ \code{NewpageBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") +block <- NewpageBlock$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/RcodeBlock.Rd b/man/RcodeBlock.Rd index 503ab959..b2e248ae 100644 --- a/man/RcodeBlock.Rd +++ b/man/RcodeBlock.Rd @@ -7,6 +7,61 @@ \code{RcodeBlock} \code{RcodeBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `RcodeBlock$new` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() + + +## ------------------------------------------------ +## Method `RcodeBlock$set_params` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$set_params(list(echo = TRUE)) + + +## ------------------------------------------------ +## Method `RcodeBlock$get_params` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$get_params() + + +## ------------------------------------------------ +## Method `RcodeBlock$get_available_params` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$get_available_params() + + +## ------------------------------------------------ +## Method `RcodeBlock$from_list` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$from_list(list(text = "sth", params = list())) + + +## ------------------------------------------------ +## Method `RcodeBlock$to_list` +## ------------------------------------------------ + +RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$to_list() + } \keyword{internal} \section{Super class}{ @@ -57,6 +112,16 @@ Returns a \code{RcodeBlock} object with no content and no parameters. \subsection{Returns}{ \code{RcodeBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -81,6 +146,17 @@ The parameters has bearing on the rendering of this block. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$set_params(list(echo = TRUE)) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -94,6 +170,17 @@ Returns the parameters of this \code{RcodeBlock}. \subsection{Returns}{ \code{character} the parameters of this \code{RcodeBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$get_params() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -107,6 +194,17 @@ Returns an array of parameters available to this \code{RcodeBlock}. \subsection{Returns}{ a \code{character} array of parameters } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$get_available_params() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -128,6 +226,17 @@ Use the \code{get_available_params} method to get all possible parameters.} \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$from_list(list(text = "sth", params = list())) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -141,6 +250,17 @@ Convert the \code{RcodeBlock} to a list. \subsection{Returns}{ \verb{named list} with a text and \code{params}. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{RcodeBlock <- getFromNamespace("RcodeBlock", "teal.reporter") +block <- RcodeBlock$new() +block$to_list() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/Renderer.Rd b/man/Renderer.Rd index 990d95c2..98d22609 100644 --- a/man/Renderer.Rd +++ b/man/Renderer.Rd @@ -7,6 +7,106 @@ \code{Renderer} \code{Renderer} +} +\examples{ + +## ------------------------------------------------ +## Method `Renderer$new` +## ------------------------------------------------ + +Renderer <- getFromNamespace("Renderer", "teal.reporter") +Renderer$new() + + +## ------------------------------------------------ +## Method `Renderer$renderRmd` +## ------------------------------------------------ + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card2 <- ReportCard$new() + +card2$append_text("Header 2 text", "header2") +card2$append_text("A paragraph of default text", "header2") +lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) +table_res2 <- rtables::build_table(lyt, airquality) +card2$append_table(table_res2) +card2$append_table(iris) +card2$append_rcode("2+2", echo = FALSE) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1, card2)) + +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml_l <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +md_header <- getFromNamespace("md_header", "teal.reporter") +yaml_header <- md_header(yaml::as.yaml(yaml_l)) +Renderer <- getFromNamespace("Renderer", "teal.reporter") +result_path <- Renderer$new()$renderRmd(reporter$get_blocks(), yaml_header) + + +## ------------------------------------------------ +## Method `Renderer$render` +## ------------------------------------------------ + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card2 <- ReportCard$new() + +card2$append_text("Header 2 text", "header2") +card2$append_text("A paragraph of default text", "header2") +lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) +table_res2 <- rtables::build_table(lyt, airquality) +card2$append_table(table_res2) +card2$append_table(iris) +card2$append_rcode("2+2", echo = FALSE) +Reporter <- getFromNamespace("Reporter", "teal.reporter")$new() +Reporter$append_cards(list(card1, card2)) + +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml_l <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +md_header <- getFromNamespace("md_header", "teal.reporter") +yaml_header <- md_header(yaml::as.yaml(yaml_l)) +Renderer <- getFromNamespace("Renderer", "teal.reporter") +result_path <- Renderer$new()$render(Reporter$get_blocks(), yaml_header) + + +## ------------------------------------------------ +## Method `Renderer$get_output_dir` +## ------------------------------------------------ + +Renderer <- getFromNamespace("Renderer", "teal.reporter")$new() +Renderer$get_output_dir() + } \keyword{internal} \section{Methods}{ @@ -36,6 +136,16 @@ Returns a \code{Renderer} object. \subsection{Returns}{ \code{Renderer} object. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{Renderer <- getFromNamespace("Renderer", "teal.reporter") +Renderer$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -85,6 +195,50 @@ use \code{getOption('teal.reporter.global_knitr')}. These defaults include: \subsection{Returns}{ \code{character} a \code{Rmd} text (\code{yaml} header + body), ready to be rendered. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card2 <- ReportCard$new() + +card2$append_text("Header 2 text", "header2") +card2$append_text("A paragraph of default text", "header2") +lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) +table_res2 <- rtables::build_table(lyt, airquality) +card2$append_table(table_res2) +card2$append_table(iris) +card2$append_rcode("2+2", echo = FALSE) + +Reporter <- getFromNamespace("Reporter", "teal.reporter") +reporter <- Reporter$new() +reporter$append_cards(list(card1, card2)) + +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml_l <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +md_header <- getFromNamespace("md_header", "teal.reporter") +yaml_header <- md_header(yaml::as.yaml(yaml_l)) +Renderer <- getFromNamespace("Renderer", "teal.reporter") +result_path <- Renderer$new()$renderRmd(reporter$get_blocks(), yaml_header) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -127,6 +281,48 @@ use \code{getOption('teal.reporter.global_knitr')}. These defaults include: \subsection{Returns}{ \code{character} path to the output } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card1 <- ReportCard$new() + +card1$append_text("Header 2 text", "header2") +card1$append_text("A paragraph of default text") +card1$append_plot( + ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram() +) + +ReportCard <- getFromNamespace("ReportCard", "teal.reporter") +card2 <- ReportCard$new() + +card2$append_text("Header 2 text", "header2") +card2$append_text("A paragraph of default text", "header2") +lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean) +table_res2 <- rtables::build_table(lyt, airquality) +card2$append_table(table_res2) +card2$append_table(iris) +card2$append_rcode("2+2", echo = FALSE) +Reporter <- getFromNamespace("Reporter", "teal.reporter")$new() +Reporter$append_cards(list(card1, card2)) + +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml_l <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +md_header <- getFromNamespace("md_header", "teal.reporter") +yaml_header <- md_header(yaml::as.yaml(yaml_l)) +Renderer <- getFromNamespace("Renderer", "teal.reporter") +result_path <- Renderer$new()$render(Reporter$get_blocks(), yaml_header) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -140,6 +336,16 @@ get \code{output_dir} field \subsection{Returns}{ \code{character} a \code{output_dir} field path. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{Renderer <- getFromNamespace("Renderer", "teal.reporter")$new() +Renderer$get_output_dir() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/ReportCard.Rd b/man/ReportCard.Rd index 204ff30f..5820514f 100644 --- a/man/ReportCard.Rd +++ b/man/ReportCard.Rd @@ -47,6 +47,14 @@ card <- ReportCard$new()$append_text("A paragraph of default text") card <- ReportCard$new()$append_rcode("2+2", echo = FALSE) +## ------------------------------------------------ +## Method `ReportCard$append_content` +## ------------------------------------------------ + +NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") +card <- ReportCard$new()$append_content(NewpageBlock$new()) + + ## ------------------------------------------------ ## Method `ReportCard$get_content` ## ------------------------------------------------ @@ -301,6 +309,16 @@ Appends a \code{ContentBlock} to this \code{ReportCard}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") +card <- ReportCard$new()$append_content(NewpageBlock$new()) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/TableBlock.Rd b/man/TableBlock.Rd index 5caa543d..19a41a9e 100644 --- a/man/TableBlock.Rd +++ b/man/TableBlock.Rd @@ -7,6 +7,17 @@ \code{TableBlock} \code{TableBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `TableBlock$set_content` +## ------------------------------------------------ + +TableBlock <- getFromNamespace("TableBlock", "teal.reporter") +block <- TableBlock$new() +block$set_content(iris) + } \keyword{internal} \section{Super classes}{ @@ -75,6 +86,17 @@ throws if argument is not a table-like object. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TableBlock <- getFromNamespace("TableBlock", "teal.reporter") +block <- TableBlock$new() +block$set_content(iris) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/TextBlock.Rd b/man/TextBlock.Rd index cbf47bf1..8bc9bbdb 100644 --- a/man/TextBlock.Rd +++ b/man/TextBlock.Rd @@ -7,6 +7,61 @@ \code{TextBlock} \code{TextBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `TextBlock$new` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() + + +## ------------------------------------------------ +## Method `TextBlock$set_style` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$set_style("header2") + + +## ------------------------------------------------ +## Method `TextBlock$get_style` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$get_style() + + +## ------------------------------------------------ +## Method `TextBlock$get_available_styles` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$get_available_styles() + + +## ------------------------------------------------ +## Method `TextBlock$from_list` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$from_list(list(text = "sth", style = "default")) + + +## ------------------------------------------------ +## Method `TextBlock$to_list` +## ------------------------------------------------ + +TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$to_list() + } \keyword{internal} \section{Super class}{ @@ -57,6 +112,16 @@ Returns a \code{TextBlock} object with no content and the default style. \subsection{Returns}{ \code{TextBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -81,6 +146,17 @@ The style has bearing on the rendering of this block. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$set_style("header2") + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -94,6 +170,17 @@ Returns the style of this \code{TextBlock}. \subsection{Returns}{ \code{character(1)} the style of this \code{TextBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$get_style() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -107,6 +194,17 @@ Returns an array of styles available to this \code{TextBlock}. \subsection{Returns}{ a \code{character} array of styles } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$get_available_styles() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -128,6 +226,17 @@ Use the \code{get_available_styles} method to get all possible styles.} \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$from_list(list(text = "sth", style = "default")) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -141,6 +250,17 @@ Convert the \code{TextBlock} to a list. \subsection{Returns}{ \verb{named list} with a text and style. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{TextBlock <- getFromNamespace("TextBlock", "teal.reporter") +block <- TextBlock$new() +block$to_list() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/conv_str_logi.Rd b/man/conv_str_logi.Rd index a413aee7..c3f4d2f1 100644 --- a/man/conv_str_logi.Rd +++ b/man/conv_str_logi.Rd @@ -29,4 +29,15 @@ conv_str_logi( \description{ convert a character of a \code{yaml} boolean to a logical value. } +\examples{ + +conv_str_logi <- getFromNamespace("conv_str_logi", "teal.reporter") +conv_str_logi("TRUE") +conv_str_logi("True") + +conv_str_logi("off") +conv_str_logi("n") + +conv_str_logi("sth") +} \keyword{internal} diff --git a/man/md_header.Rd b/man/md_header.Rd index 0956c380..e55000b8 100644 --- a/man/md_header.Rd +++ b/man/md_header.Rd @@ -12,4 +12,15 @@ md_header(x) \description{ wrap a \code{yaml} string to the \code{markdown} header. } +\examples{ +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(pdf_document = list(keep_tex = TRUE)) +) +md_header <- getFromNamespace("md_header", "teal.reporter") +md_header(yaml::as.yaml(yaml)) +} \keyword{internal} diff --git a/man/yaml_quoted.Rd b/man/yaml_quoted.Rd index 64866acf..39d61280 100644 --- a/man/yaml_quoted.Rd +++ b/man/yaml_quoted.Rd @@ -12,4 +12,14 @@ yaml_quoted(x) \description{ add quoted attribute for \code{yaml} package } +\examples{ +yaml_quoted <- getFromNamespace("yaml_quoted", "teal.reporter") +yaml <- list( + author = yaml_quoted("NEST"), + title = yaml_quoted("Report"), + date = yaml_quoted("07/04/2019"), + output = list(pdf_document = list(keep_tex = TRUE)) +) +yaml::as.yaml(yaml) +} \keyword{internal} From 7562421f086f67372c08e79fa7db7ae8d14d2cb9 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 18 Jan 2024 08:11:26 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 0.2.1.9015 --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dc220dee..c7ca8a79 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: teal.reporter Title: Reporting Tools for 'shiny' Modules -Version: 0.2.1.9014 -Date: 2023-12-13 +Version: 0.2.1.9015 +Date: 2024-01-18 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = "cre"), person("Maciej", "Nasinski", role = "aut"), diff --git a/NEWS.md b/NEWS.md index fa059574..05675be2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal.reporter 0.2.1.9014 +# teal.reporter 0.2.1.9015 * `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization.