shorten_string: Shorten character strings

Description Usage Arguments Value Examples

View source: R/shorten_string.R

Description

This function shortens strings that are longer than max.length chars.

Usage

1
shorten_string(s, max.length = NULL, abbr = "...")

Arguments

s

A string.

max.length

Maximum length of chars for the string.

abbr

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

Value

A shortened string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
s <- "This can be considered as very long string!"

# string is shorter than max.length, so returned as is
shorten_string(s, 60)

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

# string including "considered" is exactly of length 22 chars
shorten_string(s, 22)

sjPlot/sjmisc documentation built on Oct. 13, 2018, 10:55 p.m.