p: Inline Printing

Description Usage Arguments Value Author(s) References Examples

View source: R/helpers.R

Description

p merges elements of a vector in one string for the sake of pretty inline printing. Default parameters are read from appropriate option values (see argument description for details). This function allows you to put the results of an expression that yields a variable inline, by wrapping the vector elements with the string provided in wrap, and separating elements by main and ending separator (sep and copula). In case of a two-length vector, value specified in copula will be used as a separator. You can also control the length of provided vector by altering an integer value specified in limit argument (defaults to Inf).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
p(
  x,
  wrap = panderOptions("p.wrap"),
  sep = panderOptions("p.sep"),
  copula = panderOptions("p.copula"),
  limit = Inf,
  keep.trailing.zeros = panderOptions("keep.trailing.zeros"),
  missing = panderOptions("missing"),
  digits = panderOptions("digits"),
  round = panderOptions("round")
)

Arguments

x

an atomic vector to get merged for inline printing

wrap

a string to wrap vector elements (uses value set in p.wrap option: '_' by default, which is a markdown-friendly wrapper and it puts the string in italic)

sep

a string with the main separator, i.e. the one that separates all vector elements but the last two (uses the value set in p.sep option - ',' by default)

copula

a string with ending separator - the one that separates the last two vector elements (uses the value set in p.copula option, 'and' by default)

limit

maximum character length (defaults to Infinitive elements)

keep.trailing.zeros

to show or remove trailing zeros in numbers

missing

string to replace missing values

digits

numeric (default: 2) passed to format

round

numeric (default: Inf) passed to round

Value

a string with concatenated vector contents

Author(s)

Aleksandar Blagotic

References

This function was moved from rapport package: https://rapporter.github.io/rapport/.

Examples

1
2
3
4
5
6
7
8
p(c('fee', 'fi', 'foo', 'fam'))
# [1] '_fee_, _fi_, _foo_ and _fam_'
p(1:3, wrap = '')
# [1] '1, 2 and 3'
p(LETTERS[1:5], copula = 'and the letter')
# [1] '_A_, _B_, _C_, _D_ and the letter _E_'
p(c('Thelma', 'Louise'), wrap = '', copula = '&')
# [1] 'Thelma & Louise'

Example output

[1] "_fee_, _fi_, _foo_ and _fam_"
[1] "1, 2 and 3"
[1] "_A_, _B_, _C_, _D_and the letter_E_"
[1] "Thelma&Louise"

pander documentation built on June 13, 2021, 9:06 a.m.