apply_tokens: Substitute metadata tokens in text

View source: R/tokens.R

apply_tokensR Documentation

Substitute metadata tokens in text

Description

Replaces 'glue'-style '{token}' placeholders in a character vector with values taken from a user-controlled 'metadata' list. This lets study-level information (e.g. study number, data cut-off date) be injected into slide titles, footnotes and placeholder slides without editing the deck or the spec text directly.

Usage

apply_tokens(text, metadata = NULL)

Arguments

text

'character' vector possibly containing '{token}' placeholders.

metadata

Named 'list' (or 'NULL') supplying token values. Typically the spec entry produced by [read_spec()], into which the 'metadata' argument has already been merged.

Details

Token values are looked up first in 'metadata', then in the calling environment (preserving the existing 'glue' behavior used across 'decorate' methods). A '{token}' that resolves to neither raises an informative error, so typos are caught early rather than silently producing a broken slide.

Value

A length-one 'character' ('glue') value with tokens substituted and the input collapsed by newlines, matching the previous 'glue::glue()' behavior.

Examples

apply_tokens("Demographics - Study {study}", list(study = "BP12345"))
apply_tokens(c("Line 1 {study}", "Line 2"), list(study = "BP12345"))

autoslider.core documentation built on Sept. 29, 2026, 5:08 p.m.