Learn R Programming

rapport (version 0.3)

p: Inline Printing

Description

p merges elements of a variable (see is.variable) 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 20).

Usage

p(x, wrap = getOption("p.wrap"),
    sep = getOption("p.sep"),
    copula = getOption("p.copula"), limit = 20L)

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 20 elements)

Value

  • a string with concatenated vector contents

Examples

Run this code
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"

Run the code above in your browser using DataLab