Skip to contents

Version of the sprintf base R function that adds basic templating – https://stackoverflow.com/a/55423080/2047693.

Usage

sprintf_named(template, ..., .check = TRUE)

Arguments

template

template

...

Named arguments with strings that fill template variables of the same name between %{ and }s

.check

Should the consistency between the arguments and the template be checked?

Details

Because this is based on the sprintf function, use %% when you would like a single % to appear in the template. However, when supplying a single % to a named argument will result in a single % in the output.

You can use syntactically invalid names for arguments by enclosing them in backticks in the argument list, but not in the template.

Examples

sprintf_named("You might like to download datasets from %{repo}s.", repo = "IIDDA")
#> [1] "You might like to download datasets from IIDDA."