plu (version 0.1.1)

plu_stick: Collapse character vectors into natural language strings

Description

Collapse character vectors into natural language strings

Usage

plu_stick(
  x,
  fn = NULL,
  ...,
  max = Inf,
  fn_overflow = FALSE,
  sep = ", ",
  conj = " and ",
  syndeton = c("last", "all", "none"),
  oxford = getOption("plu.oxford_comma")
)

stick( x, fn = NULL, ..., max = Inf, fn_overflow = FALSE, sep = ", ", conj = " and ", syndeton = c("last", "all", "none"), oxford = getOption("plu.oxford_comma") )

Arguments

x

A character vector (or a vector coercible to character)

fn

A function to apply to all items in the list

...

Additional arguments to fn

max

The maximum number of items to list. Additional arguments are replaced with "n more". Defaults to Inf, which prints all items.

fn_overflow

Whether to apply fn to the overflow message when x contains more items than max. Defaults to FALSE.

sep

The mark to place between list items. Defaults to ", "

conj

A conjunction to place between list items. Defaults to "and".

syndeton

Whether to place the conjunction before the "last" list items, between "all" list items, or between "none". Defaults to "last".

oxford

A logical value indicating whether to place sep before the last list item (x, y, and z) or not (x, y and z) in lists of length three or more where syndeton is "last". Defaults to TRUE if R's locale is set to the United States and FALSE otherwise. The default can be changed by setting options(plu.oxford_comma).

Value

A character vector of length 1

Examples

Run this code
# NOT RUN {
ingredients <- c("sugar", "spice", "everything nice")
plu::stick(ingredients)

plu::stick(ingredients, fn = toupper)
plu::stick(names(formals(plu::stick)), fn = encodeString, quote = "`")

plu::stick(ingredients, conj = "or")

plu::stick(ingredients, syndeton = "all")

plu::stick(ingredients, sep = "/", syndeton = "none")

creed <- c("snow", "rain", "heat", "gloom of night")
plu::stick(creed, conj = "nor", syndeton = "all")

dedication <- c("my parents", "Ayn Rand", "God")
plu::stick(dedication)
plu::stick(dedication, oxford = TRUE)
plu::stick(dedication, oxford = FALSE)
# }

Run the code above in your browser using DataCamp Workspace