Learn R Programming

mighty.component (version 0.2.0)

mighty_component_rendered: Rendered mighty component class

Description

R6 class for a rendered component, created by mighty_component$render() or get_rendered_component().

A rendered component can be:

  • Streamed into an R script with $stream().

  • Evaluated in an environment with $eval().

Arguments

Super class

mighty_component -> mighty_component_rendered

Methods

Inherited methods

mighty_component_rendered$new()

Create a rendered component from a rendered template. The code is validated. See the Validation section in mighty_component.

Usage

mighty_component_rendered$new(template, id)

Arguments

template

character Rendered template, one element per line.

id

character(1) Component ID.


mighty_component_rendered$print()

Print the rendered component, including its code.

Usage

mighty_component_rendered$print()

Returns

(invisible) self


mighty_component_rendered$stream()

Write the code to an R script. The code is appended if the file exists.

Usage

mighty_component_rendered$stream(path)

Arguments

path

character(1) Path to the R script.

Returns

(invisible) self


mighty_component_rendered$eval()

Evaluate the code.

Usage

mighty_component_rendered$eval(envir = parent.frame())

Arguments

envir

Environment to evaluate the code in. Defaults to the calling environment.

Returns

Value of the last evaluated expression of the code.


mighty_component_rendered$clone()

The objects of this class are cloneable with this method.

Usage

mighty_component_rendered$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

See Also

get_rendered_component(), mighty_component

Examples

Run this code
path <- system.file("examples", "ady.mustache", package = "mighty.component")
x <- get_component(path)$render(
  domain = "adae",
  variable = "ASTDY",
  date = "ASTDT"
)
x$code

# Write the code to an R script
script <- tempfile(fileext = ".R")
x$stream(script)
readLines(script)
unlink(script)

if (FALSE) { # rlang::is_installed(c("admiral", "dplyr"))
# Evaluate the code in a new environment
env <- new.env()
env$adae <- data.frame(
  TRTSDT = as.Date("2024-01-01"),
  ASTDT = as.Date(c("2024-01-01", "2024-01-10"))
)
x$eval(envir = env)
env$adae
}

Run the code above in your browser using DataLab