Learn R Programming

insight (version 0.20.5)

format_string: String Values Formatting

Description

String Values Formatting

Usage

format_string(x, ...)

# S3 method for character format_string(x, length = NULL, abbreviate = "...", ...)

Value

A formatted string.

Arguments

x

String value.

...

Arguments passed to or from other methods.

length

Numeric, maximum length of the returned string. If not NULL, will shorten the string to a maximum length, however, it will not truncate inside words. I.e. if the string length happens to be inside a word, this word is removed from the returned string, so the returned string has a maximum length of length, but might be shorter.

abbreviate

String that will be used as suffix, if x was shortened.

Examples

Run this code
s <- "This can be considered as very long string!"
# string is shorter than max.length, so returned as is
format_string(s, 60)

# string is shortened to as many words that result in
# a string of maximum 20 chars
format_string(s, 20)

Run the code above in your browser using DataLab