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..ed7c2e4e 100644 --- a/R/Archiver.R +++ b/R/Archiver.R @@ -6,6 +6,8 @@ Archiver <- R6::R6Class( # nolint: object_name_linter. #' @description Returns an `Archiver` object. #' #' @return an `Archiver` object + #' @examples + #' archiver <- getFromNamespace("Archiver", "teal.reporter")$new() initialize = function() { invisible(self) }, @@ -36,6 +38,8 @@ FileArchiver <- R6::R6Class( # nolint: object_name_linter. #' @description Returns a `FileArchiver` object. #' #' @return a `FileArchiver` object + #' @examples + #' archiver <- getFromNamespace("FileArchiver", "teal.reporter")$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 +54,9 @@ FileArchiver <- R6::R6Class( # nolint: object_name_linter. #' @description get `output_dir` field #' #' @return `character` a `output_dir` field path. + #' @examples + #' archiver <- getFromNamespace("FileArchiver", "teal.reporter")$new() + #' archiver$get_output_dir() get_output_dir = function() { private$output_dir } @@ -70,6 +77,21 @@ JSONArchiver <- R6::R6Class( # nolint: object_name_linter. #' @param reporter `Reporter` instance. #' #' @return invisibly self + #' @examples + #' card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() + #' reporter$append_cards(list(card1)) + #' + #' archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$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 +103,25 @@ JSONArchiver <- R6::R6Class( # nolint: object_name_linter. #' @param path `character(1)` a path to the directory with all proper files. #' #' @return `Reporter` instance. + #' @examples + #' card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() + #' reporter$append_cards(list(card1)) + #' + #' archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$new() + #' archiver$write(reporter) + #' archiver$get_output_dir() + #' + #' archiver$read()$get_cards()[[1]]$get_content() + #' blocks <- getFromNamespace("Reporter", "teal.reporter")$new()$from_reporter(archiver$read())$get_blocks() + #' doc <- getFromNamespace("Renderer", "teal.reporter")$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..119a4f4b 100644 --- a/R/ContentBlock.R +++ b/R/ContentBlock.R @@ -8,6 +8,9 @@ ContentBlock <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `ContentBlock` object with no content and the default style. #' #' @return `ContentBlock` + #' @examples + #' block <- getFromNamespace("ContentBlock", "teal.reporter")$new() + #' initialize = function() { private$content <- character(0) invisible(self) @@ -17,6 +20,10 @@ 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 + #' block <- getFromNamespace("ContentBlock", "teal.reporter")$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 +32,10 @@ ContentBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the absolute path to content of this `ContentBlock` #' #' @return `character` content of this `ContentBlock` + #' @examples + #' block <- getFromNamespace("ContentBlock", "teal.reporter")$new() + #' block$get_content() + #' get_content = function() { private$content }, diff --git a/R/FileBlock.R b/R/FileBlock.R index c0613fb8..d57686b3 100644 --- a/R/FileBlock.R +++ b/R/FileBlock.R @@ -17,6 +17,12 @@ 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 + #' block <- getFromNamespace("FileBlock", "teal.reporter") + #' 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 +39,10 @@ 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 + #' block <- getFromNamespace("FileBlock", "teal.reporter") + #' 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..d95d0611 100644 --- a/R/NewpageBlock.R +++ b/R/NewpageBlock.R @@ -9,6 +9,9 @@ NewpageBlock <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `NewpageBlock` object with no content and the default style. #' #' @return `NewpageBlock` + #' @examples + #' block <- getFromNamespace("NewpageBlock", "teal.reporter")$new() + #' initialize = function() { super$set_content("\n\\newpage\n") invisible(self) diff --git a/R/PictureBlock.R b/R/PictureBlock.R index 2e779587..2186c0d1 100644 --- a/R/PictureBlock.R +++ b/R/PictureBlock.R @@ -23,6 +23,15 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param content (`ggplot`, `grob`, `trellis`) a picture in this `PictureBlock` #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$set_content(ggplot2::ggplot(iris)) + #' + #' yblock <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$set_content(lattice::bwplot(1)) + #' + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$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 +60,10 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param title (`character(1)`) a string assigned to this `PictureBlock` #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$set_title("Title") + #' set_title = function(title) { checkmate::assert_string(title) private$title <- title @@ -59,6 +72,9 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the title of this `PictureBlock` #' #' @return the content of this `PictureBlock` + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$get_title() + #' get_title = function() { private$title }, @@ -67,6 +83,10 @@ PictureBlock <- R6::R6Class( # nolint: object_name_linter. #' @param dim `numeric` figure dimensions (width and height) in pixels, length 2. #' #' @return `self` + #' @examples + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$set_dim(c(800, 600)) + #' set_dim = function(dim) { checkmate::assert_numeric(dim, len = 2) private$dim <- dim @@ -75,6 +95,9 @@ 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 + #' block <- getFromNamespace("PictureBlock", "teal.reporter")$new() + #' block$get_dim() get_dim = function() { private$dim } diff --git a/R/RcodeBlock.R b/R/RcodeBlock.R index 2f7d67f0..676e32fb 100644 --- a/R/RcodeBlock.R +++ b/R/RcodeBlock.R @@ -12,6 +12,9 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @param ... any `rmarkdown` R chunk parameter and it value. #' #' @return `RcodeBlock` + #' @examples + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() + #' initialize = function(content = character(0), ...) { super$set_content(content) self$set_params(list(...)) @@ -24,6 +27,10 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @param params (`list`) any `rmarkdown` R chunk parameter and its value. #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$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 +40,20 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the parameters of this `RcodeBlock`. #' #' @return `character` the parameters of this `RcodeBlock` + #' @examples + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$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 + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() + #' block$get_available_params() + #' get_available_params = function() { names(knitr::opts_chunk$get()) }, @@ -48,6 +63,10 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' Use the `get_available_params` method to get all possible parameters. #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$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 +77,10 @@ RcodeBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Convert the `RcodeBlock` to a list. #' #' @return `named list` with a text and `params`. + #' @examples + #' block <- getFromNamespace("RcodeBlock", "teal.reporter")$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..a7295ce3 100644 --- a/R/Renderer.R +++ b/R/Renderer.R @@ -8,6 +8,9 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @details Returns a `Renderer` object. #' #' @return `Renderer` object. + #' @examples + #' renderer <- getFromNamespace("Renderer", "teal.reporter")$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 +31,38 @@ 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 + #' card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + #' author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + #' title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + #' date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + #' output = list(html_document = list(toc = FALSE)) + #' ) + #' + #' yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) + #' result_path <- getFromNamespace("Renderer", "teal.reporter")$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 +124,35 @@ Renderer <- R6::R6Class( # nolint: object_name_linter. #' @details `r global_knitr_details()` #' #' @return `character` path to the output + #' @examples + #' card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + #' author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + #' title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + #' date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + #' output = list(html_document = list(toc = FALSE)) + #' ) + #' + #' yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) + #' result_path <- getFromNamespace("Renderer", "teal.reporter")$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 +170,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..312edc1c 100644 --- a/R/ReportCard.R +++ b/R/ReportCard.R @@ -76,10 +76,10 @@ ReportCard <- R6::R6Class( # nolint: object_name_linter. #' #' @param content (`ContentBlock`) #' @return invisibly self + #' @examples + #' card <- ReportCard$new()$append_content(getFromNamespace("NewpageBlock", "teal.reporter")$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..52c377d1 100644 --- a/R/TableBlock.R +++ b/R/TableBlock.R @@ -24,6 +24,10 @@ TableBlock <- R6::R6Class( # nolint: object_name_linter. #' this `TableBlock` #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("TableBlock", "teal.reporter")$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..fc8b4721 100644 --- a/R/TextBlock.R +++ b/R/TextBlock.R @@ -12,6 +12,9 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @param style (`character(1)`) one of: `"default"`, `"header2"`, `"header3"` `"verbatim"` #' #' @return `TextBlock` + #' @examples + #' block <- getFromNamespace("TextBlock", "teal.reporter")$new() + #' initialize = function(content = character(0), style = private$styles[1]) { super$set_content(content) self$set_style(style) @@ -24,6 +27,10 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @param style (`character(1)`) one of: `"default"`, `"header2"`, `"header3"` `"verbatim"` #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("TextBlock", "teal.reporter")$new() + #' block$set_style("header2") + #' set_style = function(style) { private$style <- match.arg(style, private$styles) invisible(self) @@ -31,12 +38,20 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Returns the style of this `TextBlock`. #' #' @return `character(1)` the style of this `TextBlock` + #' @examples + #' block <- getFromNamespace("TextBlock", "teal.reporter")$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 + #' block <- getFromNamespace("TextBlock", "teal.reporter")$new() + #' block$get_available_styles() + #' get_available_styles = function() { private$styles }, @@ -46,6 +61,10 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' Use the `get_available_styles` method to get all possible styles. #' #' @return invisibly self + #' @examples + #' block <- getFromNamespace("TextBlock", "teal.reporter")$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 +75,10 @@ TextBlock <- R6::R6Class( # nolint: object_name_linter. #' @description Convert the `TextBlock` to a list. #' #' @return `named list` with a text and style. + #' @examples + #' block <- getFromNamespace("TextBlock", "teal.reporter")$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..6fc96062 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,15 @@ 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)) +#' ) +#' getFromNamespace("md_header", "teal.reporter").(yaml::as.yaml(yaml)) md_header <- function(x) { paste0("---\n", x, "---\n") } @@ -24,6 +42,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..558a8bfe 100644 --- a/man/Archiver.Rd +++ b/man/Archiver.Rd @@ -8,6 +8,14 @@ \code{Archiver} } +\examples{ + +## ------------------------------------------------ +## Method `Archiver$new` +## ------------------------------------------------ + +archiver <- getFromNamespace("Archiver", "teal.reporter")$new() +} \keyword{internal} \section{Methods}{ \subsection{Public methods}{ @@ -31,6 +39,14 @@ Returns an \code{Archiver} object. \subsection{Returns}{ an \code{Archiver} object } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{archiver <- getFromNamespace("Archiver", "teal.reporter")$new() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/ContentBlock.Rd b/man/ContentBlock.Rd index 9a48b63d..92a3bf78 100644 --- a/man/ContentBlock.Rd +++ b/man/ContentBlock.Rd @@ -7,6 +7,31 @@ \code{ContentBlock} \code{ContentBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `ContentBlock$new` +## ------------------------------------------------ + +block <- getFromNamespace("ContentBlock", "teal.reporter")$new() + + +## ------------------------------------------------ +## Method `ContentBlock$set_content` +## ------------------------------------------------ + +block <- getFromNamespace("ContentBlock", "teal.reporter")$new() +block$set_content("Base64 encoded picture") + + +## ------------------------------------------------ +## Method `ContentBlock$get_content` +## ------------------------------------------------ + +block <- getFromNamespace("ContentBlock", "teal.reporter")$new() +block$get_content() + } \keyword{internal} \section{Methods}{ @@ -36,6 +61,15 @@ Returns a \code{ContentBlock} object with no content and the default style. \subsection{Returns}{ \code{ContentBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("ContentBlock", "teal.reporter")$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -56,6 +90,16 @@ Sets content of this \code{ContentBlock}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("ContentBlock", "teal.reporter")$new() +block$set_content("Base64 encoded picture") + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -69,6 +113,16 @@ 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{block <- getFromNamespace("ContentBlock", "teal.reporter")$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..0e019e00 100644 --- a/man/FileArchiver.Rd +++ b/man/FileArchiver.Rd @@ -8,6 +8,21 @@ \code{RDSArchiver} } +\examples{ + +## ------------------------------------------------ +## Method `FileArchiver$new` +## ------------------------------------------------ + +archiver <- getFromNamespace("FileArchiver", "teal.reporter")$new() + +## ------------------------------------------------ +## Method `FileArchiver$get_output_dir` +## ------------------------------------------------ + +archiver <- getFromNamespace("FileArchiver", "teal.reporter")$new() +archiver$get_output_dir() +} \keyword{internal} \section{Super class}{ \code{\link[teal.reporter:Archiver]{teal.reporter::Archiver}} -> \code{FileArchiver} @@ -41,6 +56,14 @@ Returns a \code{FileArchiver} object. \subsection{Returns}{ a \code{FileArchiver} object } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{archiver <- getFromNamespace("FileArchiver", "teal.reporter")$new() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -64,6 +87,15 @@ get \code{output_dir} field \subsection{Returns}{ \code{character} a \code{output_dir} field path. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{archiver <- getFromNamespace("FileArchiver", "teal.reporter")$new() +archiver$get_output_dir() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/FileBlock.Rd b/man/FileBlock.Rd index 8ef3f115..72100003 100644 --- a/man/FileBlock.Rd +++ b/man/FileBlock.Rd @@ -7,6 +7,26 @@ \code{FileBlock} \code{FileBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `FileBlock$from_list` +## ------------------------------------------------ + +block <- getFromNamespace("FileBlock", "teal.reporter") +file_path <- tempfile(fileext = ".png") +saveRDS(iris, file_path) +block$from_list(list(basename = basename(file_path)), dirname(file_path)) + + +## ------------------------------------------------ +## Method `FileBlock$to_list` +## ------------------------------------------------ + +block <- getFromNamespace("FileBlock", "teal.reporter") +block$to_list(tempdir()) + } \keyword{internal} \section{Super class}{ @@ -66,6 +86,18 @@ The list should contain one named field, \code{"basename"}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("FileBlock", "teal.reporter") +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 +118,16 @@ 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{block <- getFromNamespace("FileBlock", "teal.reporter") +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..be8af20a 100644 --- a/man/JSONArchiver.Rd +++ b/man/JSONArchiver.Rd @@ -8,6 +8,50 @@ \code{JSONArchiver} } +\examples{ + +## ------------------------------------------------ +## Method `JSONArchiver$write` +## ------------------------------------------------ + +card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() +reporter$append_cards(list(card1)) + +archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$new() +archiver$write(reporter) +archiver$get_output_dir() + +## ------------------------------------------------ +## Method `JSONArchiver$read` +## ------------------------------------------------ + +card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() +reporter$append_cards(list(card1)) + +archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$new() +archiver$write(reporter) +archiver$get_output_dir() + +archiver$read()$get_cards()[[1]]$get_content() +blocks <- getFromNamespace("Reporter", "teal.reporter")$new()$from_reporter(archiver$read())$get_blocks() +doc <- getFromNamespace("Renderer", "teal.reporter")$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 +92,27 @@ write a \code{Reporter} instance in to this \code{JSONArchiver} object. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() +reporter$append_cards(list(card1)) + +archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$new() +archiver$write(reporter) +archiver$get_output_dir() +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -68,6 +133,31 @@ read a \code{Reporter} instance from a directory with \code{JSONArchiver}. \subsection{Returns}{ \code{Reporter} instance. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{card1 <- getFromNamespace("ReportCard", "teal.reporter")$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")$new() +reporter$append_cards(list(card1)) + +archiver <- getFromNamespace("JSONArchiver", "teal.reporter")$new() +archiver$write(reporter) +archiver$get_output_dir() + +archiver$read()$get_cards()[[1]]$get_content() +blocks <- getFromNamespace("Reporter", "teal.reporter")$new()$from_reporter(archiver$read())$get_blocks() +doc <- getFromNamespace("Renderer", "teal.reporter")$new()$render(blocks) +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/NewpageBlock.Rd b/man/NewpageBlock.Rd index 9f9020e9..17c57545 100644 --- a/man/NewpageBlock.Rd +++ b/man/NewpageBlock.Rd @@ -7,6 +7,15 @@ \code{NewpageBlock} \code{NewpageBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `NewpageBlock$new` +## ------------------------------------------------ + +block <- getFromNamespace("NewpageBlock", "teal.reporter")$new() + } \keyword{internal} \section{Super class}{ @@ -45,6 +54,15 @@ Returns a \code{NewpageBlock} object with no content and the default style. \subsection{Returns}{ \code{NewpageBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("NewpageBlock", "teal.reporter")$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/RcodeBlock.Rd b/man/RcodeBlock.Rd index 503ab959..ea4b2458 100644 --- a/man/RcodeBlock.Rd +++ b/man/RcodeBlock.Rd @@ -7,6 +7,55 @@ \code{RcodeBlock} \code{RcodeBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `RcodeBlock$new` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() + + +## ------------------------------------------------ +## Method `RcodeBlock$set_params` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$set_params(list(echo = TRUE)) + + +## ------------------------------------------------ +## Method `RcodeBlock$get_params` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$get_params() + + +## ------------------------------------------------ +## Method `RcodeBlock$get_available_params` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$get_available_params() + + +## ------------------------------------------------ +## Method `RcodeBlock$from_list` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$from_list(list(text = "sth", params = list())) + + +## ------------------------------------------------ +## Method `RcodeBlock$to_list` +## ------------------------------------------------ + +block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$to_list() + } \keyword{internal} \section{Super class}{ @@ -57,6 +106,15 @@ Returns a \code{RcodeBlock} object with no content and no parameters. \subsection{Returns}{ \code{RcodeBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -81,6 +139,16 @@ The parameters has bearing on the rendering of this block. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$set_params(list(echo = TRUE)) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -94,6 +162,16 @@ Returns the parameters of this \code{RcodeBlock}. \subsection{Returns}{ \code{character} the parameters of this \code{RcodeBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$get_params() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -107,6 +185,16 @@ Returns an array of parameters available to this \code{RcodeBlock}. \subsection{Returns}{ a \code{character} array of parameters } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$get_available_params() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -128,6 +216,16 @@ Use the \code{get_available_params} method to get all possible parameters.} \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$new() +block$from_list(list(text = "sth", params = list())) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -141,6 +239,16 @@ Convert the \code{RcodeBlock} to a list. \subsection{Returns}{ \verb{named list} with a text and \code{params}. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("RcodeBlock", "teal.reporter")$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..963aab9e 100644 --- a/man/Renderer.Rd +++ b/man/Renderer.Rd @@ -7,6 +7,92 @@ \code{Renderer} \code{Renderer} +} +\examples{ + +## ------------------------------------------------ +## Method `Renderer$new` +## ------------------------------------------------ + +renderer <- getFromNamespace("Renderer", "teal.reporter")$new() + + +## ------------------------------------------------ +## Method `Renderer$renderRmd` +## ------------------------------------------------ + +card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) +result_path <- getFromNamespace("Renderer", "teal.reporter")$new()$renderRmd(reporter$get_blocks(), yaml_header) + + +## ------------------------------------------------ +## Method `Renderer$render` +## ------------------------------------------------ + +card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) +result_path <- getFromNamespace("Renderer", "teal.reporter")$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 +122,15 @@ Returns a \code{Renderer} object. \subsection{Returns}{ \code{Renderer} object. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{renderer <- getFromNamespace("Renderer", "teal.reporter")$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -85,6 +180,44 @@ 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{card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) +result_path <- getFromNamespace("Renderer", "teal.reporter")$new()$renderRmd(reporter$get_blocks(), yaml_header) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -127,6 +260,41 @@ use \code{getOption('teal.reporter.global_knitr')}. These defaults include: \subsection{Returns}{ \code{character} path to the output } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{card1 <- getFromNamespace("ReportCard", "teal.reporter")$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 <- getFromNamespace("ReportCard", "teal.reporter")$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_l <- list( + author = getFromNamespace("yaml_quoted", "teal.reporter")("NEST"), + title = getFromNamespace("yaml_quoted", "teal.reporter")("Report"), + date = getFromNamespace("yaml_quoted", "teal.reporter")("07/04/2019"), + output = list(html_document = list(toc = FALSE)) +) + +yaml_header <- getFromNamespace("md_header", "teal.reporter")(yaml::as.yaml(yaml_l)) +result_path <- getFromNamespace("Renderer", "teal.reporter")$new()$render(reporter$get_blocks(), yaml_header) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -140,6 +308,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..f9d0b0a3 100644 --- a/man/ReportCard.Rd +++ b/man/ReportCard.Rd @@ -47,6 +47,13 @@ card <- ReportCard$new()$append_text("A paragraph of default text") card <- ReportCard$new()$append_rcode("2+2", echo = FALSE) +## ------------------------------------------------ +## Method `ReportCard$append_content` +## ------------------------------------------------ + +card <- ReportCard$new()$append_content(getFromNamespace("NewpageBlock", "teal.reporter")$new()) + + ## ------------------------------------------------ ## Method `ReportCard$get_content` ## ------------------------------------------------ @@ -301,6 +308,15 @@ Appends a \code{ContentBlock} to this \code{ReportCard}. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{card <- ReportCard$new()$append_content(getFromNamespace("NewpageBlock", "teal.reporter")$new()) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/TableBlock.Rd b/man/TableBlock.Rd index 5caa543d..848749eb 100644 --- a/man/TableBlock.Rd +++ b/man/TableBlock.Rd @@ -7,6 +7,16 @@ \code{TableBlock} \code{TableBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `TableBlock$set_content` +## ------------------------------------------------ + +block <- getFromNamespace("TableBlock", "teal.reporter")$new() +block$set_content(iris) + } \keyword{internal} \section{Super classes}{ @@ -75,6 +85,16 @@ throws if argument is not a table-like object. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TableBlock", "teal.reporter")$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..7ae29e7c 100644 --- a/man/TextBlock.Rd +++ b/man/TextBlock.Rd @@ -7,6 +7,55 @@ \code{TextBlock} \code{TextBlock} +} +\examples{ + +## ------------------------------------------------ +## Method `TextBlock$new` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() + + +## ------------------------------------------------ +## Method `TextBlock$set_style` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$set_style("header2") + + +## ------------------------------------------------ +## Method `TextBlock$get_style` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$get_style() + + +## ------------------------------------------------ +## Method `TextBlock$get_available_styles` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$get_available_styles() + + +## ------------------------------------------------ +## Method `TextBlock$from_list` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$from_list(list(text = "sth", style = "default")) + + +## ------------------------------------------------ +## Method `TextBlock$to_list` +## ------------------------------------------------ + +block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$to_list() + } \keyword{internal} \section{Super class}{ @@ -57,6 +106,15 @@ Returns a \code{TextBlock} object with no content and the default style. \subsection{Returns}{ \code{TextBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$new() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -81,6 +139,16 @@ The style has bearing on the rendering of this block. \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$set_style("header2") + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -94,6 +162,16 @@ Returns the style of this \code{TextBlock}. \subsection{Returns}{ \code{character(1)} the style of this \code{TextBlock} } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$get_style() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -107,6 +185,16 @@ Returns an array of styles available to this \code{TextBlock}. \subsection{Returns}{ a \code{character} array of styles } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$get_available_styles() + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -128,6 +216,16 @@ Use the \code{get_available_styles} method to get all possible styles.} \subsection{Returns}{ invisibly self } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$new() +block$from_list(list(text = "sth", style = "default")) + +} +\if{html}{\out{
}} + +} + } \if{html}{\out{
}} \if{html}{\out{}} @@ -141,6 +239,16 @@ Convert the \code{TextBlock} to a list. \subsection{Returns}{ \verb{named list} with a text and style. } +\subsection{Examples}{ +\if{html}{\out{
}} +\preformatted{block <- getFromNamespace("TextBlock", "teal.reporter")$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..0c4d0fbb 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..22f6e1d9 100644 --- a/man/md_header.Rd +++ b/man/md_header.Rd @@ -12,4 +12,14 @@ 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)) +) +getFromNamespace("md_header", "teal.reporter").(yaml::as.yaml(yaml)) +} \keyword{internal} diff --git a/man/yaml_quoted.Rd b/man/yaml_quoted.Rd index 64866acf..e8634e23 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}