Learn R Programming

Kmisc (version 0.5.0)

pymat: Python-style Formatting of Strings.

Description

This function allows Python-style formatting of strings, whereby text of the form {0}, {1}, ..., {n} is substituted according to the matching argument passed to .... 0 corresponds to the first argument, 1 corresponds to the second, and so on.

Usage

pymat(x, ..., collapse = ", ")

Arguments

x
A string with arguments to be replaced in the form of {0}, {1}, ..., {n}.
...
Arguments to be substituted into x.
collapse
If vectors of length greater than 1 are passed to ..., then we collapse the vectors with this separator.

Examples

Run this code
pymat(
  "My favourite fruits are: {0}, {1}, and {2}.",
  "apple", "banana", "orange"
)

pymat(
  "My favourite fruits are: {0}.",
  c("apple", "banana", "orange"), collapse=", "
)

Run the code above in your browser using DataLab