Skip to contents

[Experimental] R6 class that supports creating a report card containing text, plot, table and meta data blocks that can be appended and rendered to form a report output from a shiny app.

Methods


Method new()

Returns a ReportCard object.

Usage

Returns

a ReportCard object

Examples

card <- ReportCard$new()


Method append_table()

Appends a table to this ReportCard.

Usage

ReportCard$append_table(table)

Arguments

table

the appended table

Returns

invisibly self

Examples

card <- ReportCard$new()$append_table(iris)


Method append_plot()

Appends a plot to this ReportCard.

Usage

ReportCard$append_plot(plot, dim = NULL)

Arguments

plot

the appended plot

dim

integer vector width and height in pixels.

Returns

invisibly self

Examples

card <- ReportCard$new()$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)


Method append_text()

Appends a paragraph of text to this ReportCard.

Usage

ReportCard$append_text(text, style = TextBlock$new()$get_available_styles()[1])

Arguments

text

(character(0) or character(1)) the text

style

(character(1)) the style of the paragraph. One of: default, header, verbatim

Returns

invisibly self

Examples

card <- ReportCard$new()$append_text("A paragraph of default text")


Method append_rcode()

Appends an rmarkdown R chunk to this ReportCard.

Usage

ReportCard$append_rcode(text, ...)

Arguments

text

(character(0) or character(1)) the text

...

any rmarkdown R chunk parameter and its value.

Returns

invisibly self

Examples

card <- ReportCard$new()$append_rcode("2+2", echo = FALSE)


Method append_content()

Appends a ContentBlock to this ReportCard.

Usage

ReportCard$append_content(content)

Arguments

content

(ContentBlock)

Returns

invisibly self

Examples

NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter")
card <- ReportCard$new()$append_content(NewpageBlock$new())


Method get_content()

Returns the content of this ReportCard.

Usage

ReportCard$get_content()

Returns

list() list of TableBlock, TextBlock and PictureBlock.

Examples

card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")

card$get_content()


Method reset()

Removes all objects added to this ReportCard.

Usage

ReportCard$reset()

Returns

invisibly self


Method get_metadata()

Returns the metadata of this ReportCard.

Usage

ReportCard$get_metadata()

Returns

named list list of elements.

Examples

card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")

card$get_metadata()


Method append_metadata()

Appends metadata to this ReportCard.

Usage

ReportCard$append_metadata(key, value)

Arguments

key

(character(1)) name of meta data.

value

value of meta data.

Returns

invisibly self

Examples

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
card$get_content()
card$get_metadata()


Method get_name()

get the Card name

Usage

ReportCard$get_name()

Returns

character a Card name

Examples

ReportCard$new()$set_name("NAME")$get_name()


Method set_name()

set the Card name

Usage

ReportCard$set_name(name)

Arguments

name

character a Card name

Returns

invisibly self

Examples

ReportCard$new()$set_name("NAME")$get_name()


Method to_list()

Convert the ReportCard to a list.

Usage

ReportCard$to_list(output_dir)

Arguments

output_dir

character with a path to the directory where files will be copied.

Returns

named list a ReportCard representation.

Examples

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
card$get_content()

card$to_list(tempdir())


Method from_list()

Create the ReportCard from a list.

Usage

ReportCard$from_list(card, output_dir)

Arguments

card

named list a ReportCard representation.

output_dir

character with a path to the directory where a file will be copied.

Returns

invisibly self

Examples

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
card$get_content()

ReportCard$new()$from_list(card$to_list(tempdir()), tempdir())


Method clone()

The objects of this class are cloneable with this method.

Usage

ReportCard$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `ReportCard$new`
## ------------------------------------------------

card <- ReportCard$new()


## ------------------------------------------------
## Method `ReportCard$append_table`
## ------------------------------------------------

card <- ReportCard$new()$append_table(iris)


## ------------------------------------------------
## Method `ReportCard$append_plot`
## ------------------------------------------------

card <- ReportCard$new()$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.


## ------------------------------------------------
## Method `ReportCard$append_text`
## ------------------------------------------------

card <- ReportCard$new()$append_text("A paragraph of default text")


## ------------------------------------------------
## Method `ReportCard$append_rcode`
## ------------------------------------------------

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`
## ------------------------------------------------

card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")

card$get_content()
#> [[1]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 



## ------------------------------------------------
## Method `ReportCard$get_metadata`
## ------------------------------------------------

card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")

card$get_metadata()
#> $rc
#> [1] "a <- 2 + 2"
#> 


## ------------------------------------------------
## Method `ReportCard$append_metadata`
## ------------------------------------------------

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 
#> [[2]]
#> <PictureBlock>
#>   Inherits from: <FileBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     from_list: function (x, output_dir) 
#>     get_content: function () 
#>     get_dim: function () 
#>     get_title: function () 
#>     initialize: function (plot) 
#>     set_content: function (content) 
#>     set_dim: function (dim) 
#>     set_title: function (title) 
#>     to_list: function (output_dir) 
#>   Private:
#>     content: /tmp/Rtmp4XVYd2/file1bf2f2e941.png
#>     deep_clone: function (name, value) 
#>     dim: 800 600
#>     supported_plots: ggplot grob trellis Heatmap
#>     title: 
#>     type: 
#> 
#> [[3]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 
card$get_metadata()
#> $lm
#> 
#> Call:
#> lm(formula = Ozone ~ Solar.R, data = airquality)
#> 
#> Coefficients:
#> (Intercept)      Solar.R  
#>     18.5987       0.1272  
#> 
#> 


## ------------------------------------------------
## Method `ReportCard$get_name`
## ------------------------------------------------

ReportCard$new()$set_name("NAME")$get_name()
#> [1] "NAME"

## ------------------------------------------------
## Method `ReportCard$set_name`
## ------------------------------------------------

ReportCard$new()$set_name("NAME")$get_name()
#> [1] "NAME"

## ------------------------------------------------
## Method `ReportCard$to_list`
## ------------------------------------------------

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 
#> [[2]]
#> <PictureBlock>
#>   Inherits from: <FileBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     from_list: function (x, output_dir) 
#>     get_content: function () 
#>     get_dim: function () 
#>     get_title: function () 
#>     initialize: function (plot) 
#>     set_content: function (content) 
#>     set_dim: function (dim) 
#>     set_title: function (title) 
#>     to_list: function (output_dir) 
#>   Private:
#>     content: /tmp/Rtmp4XVYd2/file1bf4783624b.png
#>     deep_clone: function (name, value) 
#>     dim: 800 600
#>     supported_plots: ggplot grob trellis Heatmap
#>     title: 
#>     type: 
#> 
#> [[3]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 

card$to_list(tempdir())
#> $blocks
#> $blocks$TextBlock
#> $blocks$TextBlock$text
#> [1] "Some text"
#> 
#> $blocks$TextBlock$style
#> [1] "default"
#> 
#> 
#> $blocks$PictureBlock
#> $blocks$PictureBlock$basename
#> [1] "file1bf4783624b.png"
#> 
#> 
#> $blocks$TextBlock
#> $blocks$TextBlock$text
#> [1] "Some text"
#> 
#> $blocks$TextBlock$style
#> [1] "default"
#> 
#> 
#> 
#> $metadata
#> $metadata$lm
#> 
#> Call:
#> lm(formula = Ozone ~ Solar.R, data = airquality)
#> 
#> Coefficients:
#> (Intercept)      Solar.R  
#>     18.5987       0.1272  
#> 
#> 
#> 


## ------------------------------------------------
## Method `ReportCard$from_list`
## ------------------------------------------------

card <- ReportCard$new()$append_text("Some text")$append_plot(
  ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
                  value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 
#> [[2]]
#> <PictureBlock>
#>   Inherits from: <FileBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     from_list: function (x, output_dir) 
#>     get_content: function () 
#>     get_dim: function () 
#>     get_title: function () 
#>     initialize: function (plot) 
#>     set_content: function (content) 
#>     set_dim: function (dim) 
#>     set_title: function (title) 
#>     to_list: function (output_dir) 
#>   Private:
#>     content: /tmp/Rtmp4XVYd2/file1bf494256cc.png
#>     deep_clone: function (name, value) 
#>     dim: 800 600
#>     supported_plots: ggplot grob trellis Heatmap
#>     title: 
#>     type: 
#> 
#> [[3]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     from_list: function (x) 
#>     get_available_styles: function () 
#>     get_content: function () 
#>     get_style: function () 
#>     initialize: function (content = character(0), style = private$styles[1]) 
#>     set_content: function (content) 
#>     set_style: function (style) 
#>     to_list: function () 
#>   Private:
#>     content: Some text
#>     deep_clone: function (name, value) 
#>     style: default
#>     styles: default header2 header3 verbatim
#> 

ReportCard$new()$from_list(card$to_list(tempdir()), tempdir())