get_component(): Find a component. Raises an error if it is not found.get_rendered_component(): Find a component and render it withparams.
Usage
get_component(component, repos = NULL)
get_rendered_component(component, params = list(), repos = NULL)Arguments
- component
character(1)Component name. IfreposisNULL, path to a component file.- repos
Where to look. One of:
NULL(default):componentis a file path.charactervector of repo specs, in priority order. Seemighty_repo().A
mighty_repo_classobject.A
listof repo specs ormighty_repo_classobjects, in priority order.A
mighty_repos()collection.
Character vectors and lists are converted once with
mighty_repos().- params
named
listof parameters passed to$render(). See the component's@paramtags (component$params).
Value
get_component(): A mighty_component object.get_rendered_component(): A mighty_component_rendered object.
Details
Components are .mustache or .R files. Both use the tags described in
mighty_component.
.mustachefiles are Mustache templates..Rfiles are plain R components. They cannot have@paramtags or Mustache placeholders.
Examples
path <- system.file("examples", "ady.mustache", package = "mighty.component")
get_component(path)
#> → Found "ady.mustache" in "local::/home/runner/work/_temp/Library/mighty.component/examples"
#> <mighty_component/R6>
#> ady: Analysis relative day
#> Type: column
#> Parameters:
#> • domain: `character` Name of new domain being created
#> • variable: `character` Name of new variable to create
#> • date: `character` Name of date variable to use
#> Depends:
#> • {{{domain}}}.{{{date}}}
#> • {{{domain}}}.TRTSDT
#> Outputs:
#> • {{{variable}}}
get_rendered_component(
component = path,
params = list(domain = "ADAE", variable = "ASTDY", date = "ASTDT")
)
#> → Found "ady.mustache" in "local::/home/runner/work/_temp/Library/mighty.component/examples"
#> <mighty_component_rendered/mighty_component/R6>
#> ady: Analysis relative day
#> Type: column
#> Depends:
#> • ADAE.ASTDT
#> • ADAE.TRTSDT
#> Outputs:
#> • ASTDY
#> Code:
#> ADAE <- ADAE |>
#> dplyr::mutate(
#> ASTDY = admiral::compute_duration(
#> start_date = TRTSDT,
#> end_date = ASTDT,
#> in_unit = 'days',
#> out_unit = 'days',
#> add_one = TRUE
#> )
#> )
# Find by name in a repo
repo <- system.file("examples", package = "mighty.component")
get_component("ady", repos = repo)
#> → Found "ady" in "local::/home/runner/work/_temp/Library/mighty.component/examples"
#> <mighty_component/R6>
#> ady: Analysis relative day
#> Type: column
#> Parameters:
#> • domain: `character` Name of new domain being created
#> • variable: `character` Name of new variable to create
#> • date: `character` Name of date variable to use
#> Depends:
#> • {{{domain}}}.{{{date}}}
#> • {{{domain}}}.TRTSDT
#> Outputs:
#> • {{{variable}}}
