Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fill_in

Fill In Templates


Description

Light-weight template filling: replace placeholders in a string by values.

Usage

fill_in(s, ..., delim = c("{", "}"), replace.NA = TRUE)

Arguments

s

character

...

typically name/value pairs. See Examples.

delim

characters

replace.NA

logical: if TRUE, NA values are replaced by the string "NA". May also be a string. See Examples.

Details

A light-weight replacement function.

Value

character

Author(s)

Enrico Schumann

Examples

template <- "{1} meets {2}"
fill_in(template, "Peter", "Paul")  ## "Peter meets Paul"

template <- "{one} meets {other}"
fill_in(template, one = "Peter", other = "Paul")  ## "Peter meets Paul"


## handling missing values
fill_in("{name}: {score}", name = "Peter", score = NA)
## [1] "Peter: NA"

fill_in("{name}: {score}", name = "Peter", score = NA, replace.NA = ".")
## [1] "Peter: ."

textutils

Utilities for Handling Strings and Text

v0.2-1
GPL-3
Authors
Enrico Schumann [aut, cre] (<https://orcid.org/0000-0001-7601-6576>)
Initial release
2021-04-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.