Learn R Programming

jmvcore (version 2.6.3)

format: Format a string with arguments

Description

Substitutes the arguments into the argument str. See the examples below.

Usage

format(str, ..., context = "normal")

Value

the resultant string

Arguments

str

the format string

...

the arguments to substitute into the string

context

'normal' or 'R'

Examples

Run this code

jmvcore::format('the {} was delish', 'fish')

# 'the fish was delish'

jmvcore::format('the {} was more delish than the {}', 'fish', 'cow')

# 'the fish was more delish than the cow'

jmvcore::format('the {1} was more delish than the {0}', 'fish', 'cow')

# 'the cow was more delish than the fish'

jmvcore::format('the {what} and the {which}', which='fish', what='cow')

# 'the cow and the fish'

jmvcore::format('that is simply not {}', TRUE)

# 'that is simply not true'

jmvcore::format('that is simply not {}', TRUE, context='R')

# 'that is simply not TRUE'

Run the code above in your browser using DataLab