| Reporter {teal.reporter} | R Documentation |
Reporter: An R6 class for managing report cards
Description
This R6 class is designed to store and manage report cards,
facilitating the creation, manipulation, and serialization of report-related data.
Methods
Public methods
Method new()
Initialize a Reporter object.
Usage
Reporter$new()
Returns
Object of class Reporter, invisibly.
Examples
reporter <- Reporter$new()
Method append_cards()
Append one or more ReportCard objects to the Reporter.
Usage
Reporter$append_cards(cards)
Arguments
cards(
ReportCard) or a list of such objects
Returns
self, invisibly.
Examples
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
Method get_cards()
Retrieves all ReportCard objects contained in the Reporter.
Usage
Reporter$get_cards()
Returns
A (list) of ReportCard objects.
Examples
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_cards()
Method get_blocks()
Compiles and returns all content blocks from the ReportCard in the Reporter.
Usage
Reporter$get_blocks(sep = NewpageBlock$new())
Arguments
sepAn optional separator to insert between each content block. Default is a
NewpageBlock$new()object.
Returns
list() list of TableBlock, TextBlock, PictureBlock and NewpageBlock.
Examples
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_blocks()
Method reset()
Resets the Reporter, removing all ReportCard objects and metadata.
Usage
Reporter$reset()
Returns
self, invisibly.
Method remove_cards()
Removes specific ReportCard objects from the Reporter by their indices.
Usage
Reporter$remove_cards(ids = NULL)
Arguments
ids(
integer(id)) the indexes of cards
Returns
self, invisibly.
Method swap_cards()
Swaps the positions of two ReportCard objects within the Reporter.
Usage
Reporter$swap_cards(start, end)
Arguments
start(
integer) the index of the first cardend(
integer) the index of the second card
Returns
self, invisibly.
Method get_reactive_add_card()
Gets the current value of the reactive variable for adding cards.
Usage
Reporter$get_reactive_add_card()
Returns
reactive_add_card current numeric value of the reactive variable.
Examples
library(shiny) isolate(Reporter$new()$get_reactive_add_card())
Method get_metadata()
Get the metadata associated with this Reporter.
Usage
Reporter$get_metadata()
Returns
named list of metadata to be appended.
Examples
reporter <- Reporter$new()$append_metadata(list(sth = "sth")) reporter$get_metadata()
Method append_metadata()
Appends metadata to this Reporter.
Usage
Reporter$append_metadata(meta)
Arguments
meta(
named list) of metadata to be appended.
Returns
self, invisibly.
Examples
reporter <- Reporter$new()$append_metadata(list(sth = "sth")) reporter$get_metadata()
Method from_reporter()
Reinitializes a Reporter instance by copying the report cards and metadata from another Reporter.
Usage
Reporter$from_reporter(reporter)
Arguments
reporter(
Reporter) instance to copy from.
Returns
self, invisibly.
Examples
reporter <- Reporter$new() reporter$from_reporter(reporter)
Method to_list()
Convert a Reporter to a list and transfer any associated files to specified directory.
Usage
Reporter$to_list(output_dir)
Arguments
output_dir(
character(1)) a path to the directory where files will be copied.
Returns
named list representing the Reporter instance, including version information,
metadata, and report cards.
Examples
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "testdir") dir.create(tmp_dir) reporter$to_list(tmp_dir)
Method from_list()
Reinitializes a Reporter from a list representation and associated files in a specified directory.
Usage
Reporter$from_list(rlist, output_dir)
Arguments
rlist(
named list) representing aReporterinstance.output_dir(
character(1)) a path to the directory from which files will be copied.
Returns
self, invisibly.
Examples
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "testdir") unlink(tmp_dir, recursive = TRUE) dir.create(tmp_dir) reporter$from_list(reporter$to_list(tmp_dir), tmp_dir)
Method to_jsondir()
Serializes the Reporter to a JSON file and copies any associated files to a specified directory.
Usage
Reporter$to_jsondir(output_dir)
Arguments
output_dir(
character(1)) a path to the directory where files will be copied,JSONand statics.
Returns
output_dir argument.
Examples
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "jsondir") dir.create(tmp_dir) reporter$to_jsondir(tmp_dir)
Method from_jsondir()
Reinitializes a Reporter from a JSON file and files in a specified directory.
Usage
Reporter$from_jsondir(output_dir)
Arguments
output_dir(
character(1)) a path to the directory with files,JSONand statics.
Returns
self, invisibly.
Examples
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "jsondir") dir.create(tmp_dir) unlink(list.files(tmp_dir, recursive = TRUE)) reporter$to_jsondir(tmp_dir) reporter$from_jsondir(tmp_dir)
Method clone()
The objects of this class are cloneable with this method.
Usage
Reporter$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Note
The function has to be used in the shiny reactive context.
Examples
## ------------------------------------------------
## Method `Reporter$new`
## ------------------------------------------------
reporter <- Reporter$new()
## ------------------------------------------------
## Method `Reporter$append_cards`
## ------------------------------------------------
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
## ------------------------------------------------
## Method `Reporter$get_cards`
## ------------------------------------------------
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_cards()
## ------------------------------------------------
## Method `Reporter$get_blocks`
## ------------------------------------------------
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_blocks()
## ------------------------------------------------
## Method `Reporter$get_reactive_add_card`
## ------------------------------------------------
library(shiny)
isolate(Reporter$new()$get_reactive_add_card())
## ------------------------------------------------
## Method `Reporter$get_metadata`
## ------------------------------------------------
reporter <- Reporter$new()$append_metadata(list(sth = "sth"))
reporter$get_metadata()
## ------------------------------------------------
## Method `Reporter$append_metadata`
## ------------------------------------------------
reporter <- Reporter$new()$append_metadata(list(sth = "sth"))
reporter$get_metadata()
## ------------------------------------------------
## Method `Reporter$from_reporter`
## ------------------------------------------------
reporter <- Reporter$new()
reporter$from_reporter(reporter)
## ------------------------------------------------
## Method `Reporter$to_list`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "testdir")
dir.create(tmp_dir)
reporter$to_list(tmp_dir)
## ------------------------------------------------
## Method `Reporter$from_list`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "testdir")
unlink(tmp_dir, recursive = TRUE)
dir.create(tmp_dir)
reporter$from_list(reporter$to_list(tmp_dir), tmp_dir)
## ------------------------------------------------
## Method `Reporter$to_jsondir`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "jsondir")
dir.create(tmp_dir)
reporter$to_jsondir(tmp_dir)
## ------------------------------------------------
## Method `Reporter$from_jsondir`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "jsondir")
dir.create(tmp_dir)
unlink(list.files(tmp_dir, recursive = TRUE))
reporter$to_jsondir(tmp_dir)
reporter$from_jsondir(tmp_dir)