f_wrap: Wrap Strings

Description Usage Arguments Value See Also Examples

Description

Wrap strings by splitting n width, and paste collapsing with new line characters.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
f_wrap(
  x,
  width = 15,
  sep = "\n",
  exdent = 0,
  indent = 0,
  equal.lines = FALSE,
  collapse = FALSE,
  ...
)

ff_wrap(...)

Arguments

x

A vector of text strings.

width

A positive integer giving the target column for wrapping lines in the output.

sep

A new line separator (defaults to "\n".

exdent

A non-negative integer specifying the indentation of subsequent lines in paragraphs.

indent

A non-negative integer giving the indentation of the first line in a paragraph.

equal.lines

logical. If TRUE the number of lines for each element will be made the same by appending additional '\n' to those below the max number of lines. This is useful for legend spacing.

collapse

logical. If TRUE then x is collapsed via paste(x, collapse = ' ') before processing. This is useful for muti-line text wrapping of longer subtitles.

...

Other arguments passed to strwrap.

Value

Returns a string vector with wrapped new line characters.

See Also

strwrap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
cat(f_wrap('really long label names are the pits'))
cat(f_wrap('really long label names are the pits', width = 20, exdent = 2))
f_wrap(c('really long label names are the pits and make us sad',
    'not nearly so long'), equal.lines = TRUE)

## Not run: 
library(tidyverse); library(gridExtra)

set.seed(10)
dat <- data_frame(
    level = c('Not Involved', 'Somewhat Involved Single Group',
        'Somewhat Involved Multiple Groups', 'Very Involved One Group',
        'Very Involved Multiple Groups'
    ),
    n = sample(1:10, length(level))
) %>%
    mutate(
        level = factor(level, levels = unique(level)),
        `%` = n/sum(n)
    )

gridExtra::grid.arrange(
    dat %>%
        ggplot(aes(level, `%`)) +
            geom_col() +
            labs(title = 'Yucky Labels', y = NULL),

    dat %>%
        ggplot(aes(level, `%`)) +
            geom_col() +
            scale_x_discrete(labels = f_wrap) +
            scale_y_continuous(labels = ff_prop2percent(digits = 0)) +
            labs(title = 'Happy Labels', y = NULL),

    ncol = 1, heights = c(.45, .55)
)


## End(Not run)

numform documentation built on Oct. 10, 2021, 1:10 a.m.