word_wrap: Insert line breaks in long labels

Description Usage Arguments Value Examples

View source: R/word_wrap.R

Description

Insert line breaks in long character strings. Useful if you want to wordwrap labels / titles for plots or tables.

Usage

1
word_wrap(labels, wrap, linesep = NULL)

Arguments

labels

Label(s) as character string, where a line break should be inserted. Several strings may be passed as vector (see 'Examples').

wrap

Maximum amount of chars per line (i.e. line length). If wrap = Inf or wrap = 0, no word wrap will be performed (i.e. labels will be returned as is).

linesep

By default, this argument is NULL and a regular new line string ("\n") is used. For HTML-purposes, for instance, linesep could be "<br>".

Value

New label(s) with line breaks inserted at every wrap's position.

Examples

1
2
3
word_wrap(c("A very long string", "And another even longer string!"), 10)

message(word_wrap("Much too long string for just one line!", 15))

Example output

sh: 1: cannot create /dev/null: Permission denied
sh: 1: wc: Permission denied
Could not detect number of cores, defaulting to 1.
[1] "A very\nlong\nstring"                "And\nanother\neven\nlonger\nstring!"
Much too long
string for just
one line!

sjmisc documentation built on Dec. 11, 2021, 9:34 a.m.