| Title: | Mighty Components for ADaM Generation |
|---|---|
| Description: | Components to be used inside the 'mighty' framework for generation of ADaM programs. |
| Authors: | Aksel Thomsen [aut, cre], Matthew Phelps [aut], Novo Nordisk A/S [cph] |
| Maintainer: | Aksel Thomsen <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.1.0.9001 |
| Built: | 2026-06-05 11:33:09 UTC |
| Source: | https://github.com/NovoNordisk-OpenSource/mighty.component |
Retrieve a mighty code component.
get_component(): Returns an object of class mighty_component.
get_rendered_component(): Returns an object of class mighty_component_rendered.
When rendering a component the required list of parameters depends on the individual component. Check the documentation of the local component for details.
get_component(component, repos = NULL) get_rendered_component(component, params = list(), repos = NULL)get_component(component, repos = NULL) get_rendered_component(component, params = list(), repos = NULL)
component |
|
repos |
prioritized |
params |
named |
Processes different component types based on file extension:
.R: Extracts and renders custom functions.
.mustache: Creates components from the template files.
The repos parameter accepts a character vector of locations to search,
in priority order. Each element is either a local directory path or a
GitHub source in owner/repo, owner/repo/subdir, or owner/repo@ref
format. The first match is returned. Defaults to the current directory.
mighty_component, mighty_component_rendered
path <- system.file("examples", "ady.mustache", package = "mighty.component") get_component(path)path <- system.file("examples", "ady.mustache", package = "mighty.component") get_component(path)
Creates a mighty_component_test object from a rendered component,
enabling structured unit testing with optional coverage checking.
See mighty_component_test for a description of the testing workflow.
get_test_component( component, params = list(), repos = NULL, check_coverage = TRUE, teardown_env = parent.frame() )get_test_component( component, params = list(), repos = NULL, check_coverage = TRUE, teardown_env = parent.frame() )
component |
|
params |
named |
repos |
prioritized |
check_coverage |
|
teardown_env |
The environment in which to register the deferred
coverage check. Defaults to the caller's environment ( |
A mighty_component_test object.
get_rendered_component(), mighty_component_test
List all available mighty components (.R and .mustache files)
in the specified directories.
list_components(path, as = c("character", "list", "tibble"))list_components(path, as = c("character", "list", "tibble"))
path |
|
as |
Format to list the components in.
Default |
Depending on as:
character: vector of component IDs
list: list of component metadata
(id, title, description, params, depends, outputs, code)
tibble: tibble with one row per component
path <- system.file("examples", package = "mighty.component") list_components(path) list_components(path, as = "list") |> str(max.level = 1)path <- system.file("examples", package = "mighty.component") list_components(path) list_components(path, as = "list") |> str(max.level = 1)
Class for a generic mighty component.
In the mighty framework, a "component" is a code template that processes input data and returns a modified version with new columns or rows. Mighty components share a common structure and roxygen-like documentation pattern, facilitating their use inside mighty.
Templates are character vectors of R code that are interpreted.
Dynamic use of variables etc. are supported using the mustache
framework. Dynamic parameters are specified using {{ variable_name }}.
A template is required to be documented with the following tags similar to when documenting functions using roxygen2:
| Tag | Description | Example |
@title |
Title of the component | @title My component |
@description |
Description of the component | @description text text |
@param |
Specifies input used to render the component | @param variable new var |
@type |
Specifies type: column, row, parameter, internal | @type column |
@origin |
CDISC origin (optional) | @origin Derived |
@depends |
Required input variable (repeat if several) | @depends {{ domain }} USUBJID |
@outputs |
Variables created (repeat if several) | @outputs NEWVAR |
@code |
Everything under this tag defines the component code | @code
|
A component template follows these conventions:
The input data set is always called {{ domain }}.
Additional parameters used to render the template into R code are documented with the @param tag.
The template ends with creating a modified version of {{ domain }}.
Template documented with the roxygen-like tags above
Below is an example of a mighty component template that
creates a new dynamic variable variable as twice the value
of the dynamic input x, that should already by in the input data set {{ domain }}.
#' @title Title for my component
#' @description
#' A more in depth description of what is being done
#'
#' @param variable dynamic output if applicable
#' @param x some other input to the component
#' @type column
#' @origin Derived
#' @depends {{ domain }} {{ x }}
#' @outputs {{ variable }}
#' @code
{{ domain }} <- {{ domain }} |>
dplyr::mutate(
{{ variable }} = 2 * {{ x }}
)
When rendered with parameters variable = "A" and x = "B"
the rendered code used in mighty becomes:
{{ domain }} <- {{ domain }} |>
dplyr::mutate(
A = 2 * B
)
idComponent ID.
titleTitle for the component.
descriptionDescription of the component.
codeThe code block of the component.
templateThe complete template.
typeThe type of the component. Can be one of column, row, parameter, internal.
originCDISC origin. One of Assigned, Collected, Derived, Not Available, Other, Predecessor, Protocol or NULL.
dependsData.frame listing all the components dependencies.
outputsList of the new columns created by the component.
paramsData.frame listing parameters that need to be supplied when rendering the component.
new()
Create component from template.
mighty_component$new(template, id)
templatecharacter template code. See details for how to format.
idcharacter ID of the component.
print()
Print method displaying the component information.
mighty_component$print()
(invisible) self
render()
Render component with supplied values.
Supports mustache templates and uses whisker::whisker.render().
mighty_component$render(...)
...Parameters used to render the template. Must be named, and depends on the template.
Object of class mighty_component_rendered
document()
Create standard documentation in markdown format.
mighty_component$document()
clone()
The objects of this class are cloneable with this method.
mighty_component$clone(deep = FALSE)
deepWhether to make a deep clone.
get_component(), mighty_component_rendered
Class for a rendered mighty component.
Once rendered a component can be used to:
Stream into an R script
Evaluate the generated code in an environment
mighty.component::mighty_component -> mighty_component_rendered
new()
Create component from rendered template.
mighty_component_rendered$new(template, id)
templatecharacter Rendered template such as output from mighty_component$render().
idcharacter ID of the component.
print()
Print rendered component
mighty_component_rendered$print()
(invisible) self
stream()
Stream rendered code into a script (appended)
mighty_component_rendered$stream(path)
pathcharacter(1) path to the R script to stream code into.
eval()
Evaluate code in a specified environment.
mighty_component_rendered$eval(envir = parent.frame())
envirEnvironment to evaluate in. Parsed to eval().
Defaults to using the current environment with parent.frame().
clone()
The objects of this class are cloneable with this method.
mighty_component_rendered$clone(deep = FALSE)
deepWhether to make a deep clone.
Class for unit testing a mighty component with code coverage tracking. Runs component code in an isolated R session and tracks which lines are executed during testing.
Always use get_test_component() to create instances for testing. The test
workflow is:
Create test component with get_test_component()
Assign input data with $assign()
Execute and track coverage with $eval()
Retrieve results with $get()
Test results with expect_*() functions from {testthat}
Coverage is automatically checked at test teardown via $check_coverage().
mighty.component::mighty_component -> mighty.component::mighty_component_rendered -> mighty_component_test
percent_coveragenumeric Percentage of lines covered (0-100).
line_coveragedata.frame with columns line and value
showing execution count per line.
new()
Create test component from rendered template.
mighty_component_test$new(template, id)
templatecharacter Rendered template such as output from mighty_component$render().
idcharacter ID of the component.
print()
Print method showing component and test coverage
mighty_component_test$print()
assign()
Assign a variable in the isolated test session.
mighty_component_test$assign(x, value)
xcharacter Name of the variable to assign.
valueValue to assign to the variable.
self invisibly, for method chaining.
get()
Retrieve a variable from the isolated test session.
mighty_component_test$get(x)
xcharacter Name of the variable to retrieve.
The value of the variable.
ls()
List all objects in the isolated test session.
mighty_component_test$ls()
character vector of variable names.
eval()
Execute the component code and update coverage tracking.
mighty_component_test$eval()
self invisibly, for method chaining.
check_coverage()
Check that all lines in the component were executed at least once. Throws an error if any lines have zero coverage.
mighty_component_test$check_coverage()
self invisibly if all lines are covered.
clone()
The objects of this class are cloneable with this method.
mighty_component_test$clone(deep = FALSE)
deepWhether to make a deep clone.
Verbosity level for functions in mighty.component. See zephyr::verbosity_level for details.
Default: NA_character_
Option: mighty.component.verbosity_level
Environment: R_MIGHTY.COMPONENT_VERBOSITY_LEVEL