Inserts line breaks into a longer message or warning string. Line length is adjusted to maximum length of the console, if the width can be accessed. By default, new lines are indented by two whitespace.

## Usage

format_message(string, ..., line_length = 0.9 * options()\$width)

## Arguments

string

A string.

...

Further strings that will be concatenated as indented new lines.

line_length

Numeric, the maximum length of a line.

## Value

A formatted string.

## Details

There is an experimental formatting feature implemented in this function. You can use following tags:

• {.b text} for bold formatting

• {.i text} to use italic font style

• {.url www.url.com} formats the string as URL (i.e., enclosing URL in < and >, blue color and italic font style)

• {.pkg packagename} formats the text in blue color.

This features has some limitations: it's hard to detect the exact length for each line when the string has multiple lines (after line breaks) and the string contains formatting tags. Thus, it can happen that lines are wrapped at an earlier length than expected. Furthermore, if you have multiple words in a format tag ({.b one two three}), a line break might occur inside this tag, and the formatting no longer works (messing up the message-string).

## Examples

msg <- format_message("Much too long string for just one line, I guess!",
line_length = 15
)
message(msg)
#> Much too long
#>   string for just
#>   one line, I
#>   guess!

msg <- format_message("Much too long string for just one line, I guess!",
"First new line",
"Second new line",
"(both indented)",
line_length = 30
)
message(msg)
#> Much too long string for just
#>   one line, I guess!
#>   First new line
#>   Second new line
#>   (both indented)

# Caution, experimental! See 'Details'
msg <- format_message(
"This is {.i italic}, visit {.url easystats.github.io/easystats}",
line_length = 30
)
message(msg)
#> This is italic, visit
#>   easystats.github.io/easystats