Learn R Programming

report (version 0.4.0)

format_text: Convenient text formatting functionalities

Description

Convenience functions to manipulate and format text.

Usage

format_text(text, sep = ", ", last = " and ", width = NULL, ...)

text_fullstop(text)

text_lastchar(text, n = 1)

text_concatenate(text, sep = ", ", last = " and ")

text_paste(text, text2 = NULL, sep = ", ", ...)

text_remove(text, pattern = "", ...)

text_wrap(text, width = NULL, ...)

Arguments

text, text2

A character string.

sep

Separator.

last

Last separator.

width

Positive integer giving the target column width for wrapping lines in the output. Can be "auto", in which case it will select 90\ default width.

...

Other arguments to be passed to or from other functions.

n

The number of characters to find.

pattern

Character strings.

Value

A character string.

Examples

Run this code
# NOT RUN {
library(report)

# Add full stop if missing
text_fullstop(c("something", "something else."))

# Find last characters
text_lastchar(c("ABC", "DEF"), n = 2)

# Smart concatenation
text_concatenate(c("First", "Second", "Last"))

# Remove parts of string
text_remove(c("one!", "two", "three!"), "!")

# Wrap text
long_text <- paste(rep("abc ", 100), collapse = "")
cat(text_wrap(long_text, width = 50))

# Paste with optional separator
text_paste(c("A", "", "B"), c("42", "42", "42"))
# }

Run the code above in your browser using DataLab