Learn R Programming

plu (version 0.2.1)

plu_stick: Collapse a vector into a natural language string

Description

Collapse a vector into a natural language string

Usage

plu_stick(
  x,
  sep = ", ",
  conj = " and ",
  oxford = getOption("plu.oxford_comma", FALSE),
  syndeton = lifecycle::deprecated(),
  fn = lifecycle::deprecated(),
  ...
)

stick( x, sep = ", ", conj = " and ", oxford = getOption("plu.oxford_comma", FALSE), syndeton = lifecycle::deprecated(), fn = lifecycle::deprecated(), ... )

Arguments

x

A character vector (or a vector coercible to character).

sep

A character to place between list items. Defaults to ", "

conj

A character to place between the penultimate and last list items. Defaults to " and ". If NULL, sep is used.

oxford

A logical indicating whether to place sep before conj (x, y, and z) or not (x, y and z) in lists of length three or more. Defaults to FALSE. The default can be changed by setting options(plu.oxford_comma).

syndeton

deprecated

fn

deprecated

...

deprecated

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, conj = " or ")

# When `conj` is `NULL`, `sep` is used between all elements
plu::stick(ingredients, sep = " and ", conj = NULL)
plu::stick(ingredients, sep = "/",     conj = NULL)

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

# Oxford commas are only added when there are three or more elements
plu::stick(letters[1:3], oxford = TRUE)
plu::stick(letters[1:2], oxford = TRUE)

# Oxford commas are optional for English, but should be FALSE for most languages
ingredientes <- c("az<U+00C3><U+00BA>car", "flores", "muchos colores")
plu::stick(ingredientes, conj = " y ", oxford = FALSE)
# }

Run the code above in your browser using DataLab