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.
Details
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 }}.
Documentation
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: predecessor, derivation, row | @type derivation |
@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 |
Conventions
A template for a standard components follow these conventions:
The input data set is always called
{{ domain }}.Additional parameters used to render the template into R code are documented with the
@paramtag.The template ends with creating a modified version of
{{ domain }}.Template documented with the roxygen-like tags above
Example
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 derivation
#' @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
)Active bindings
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 predecessor, derivation, row.
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.
Methods
Method print()
Print method displaying the component information.
Method render()
Render component with supplied values.
Supports mustache templates and uses whisker::whisker.render().
Returns
Object of class mighty_component_rendered
