Skip to contents

[Experimental]

The teal_card S3 class provides functionality to store, manage, edit, and adjust report contents. It enables users to create, manipulate, and serialize report-related data efficiently.

The teal_card() function serves two purposes:

  1. When called with a teal_report object, it acts as a getter and returns the card slot.

  2. When called with other arguments, it creates a new teal_card object from those arguments.

This function ensures that input is converted to a teal_card object. It accepts various input types and converts them appropriately.

Usage

teal_card(...)

teal_card(x) <- value

as.teal_card(x)

# S3 method for class 'teal_card'
c(...)

# S3 method for class 'teal_card'
x[i]

Arguments

...

Elements from which teal_card will be combined.

x

Object to convert to teal_card

value

(teal_card) object to set in the teal_report.

i

index specifying elements to extract or replace

Value

An S3 list of class teal_card.

A teal_card object

Details

The teal_card class supports c() and x[i] methods for combining and subsetting elements. However, these methods only function correctly when the first element is a teal_card.

Examples

# Create a new empty card
report <- teal_card()

# Create a card with content
report <- teal_card("## Headline", "Some text", summary(iris))

# Extract card from a teal_report
tr <- teal_report(teal_card = teal_card("## Title"))
doc <- teal_card(tr)

# Add elements to the report
report <- c(report, list("## Table"), list(summary(mtcars)))

# Subset the report to keep only the first two elements
report <- report[1:2]

# Append new elements after the first element
report <- append(report, c(list("## Table 2"), list(summary(mtcars))), after = 1)

# Verify that the object remains a teal_card
class(report)
#> [1] "teal_card"