Collapse a vector into a natural language string

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

ingredients <- c("sugar", "spice", "everything nice") plu::stick(ingredients)
#> [1] "sugar, spice and everything nice"
plu::stick(ingredients, conj = " or ")
#> [1] "sugar, spice or everything nice"
# When `conj` is `NULL`, `sep` is used between all elements plu::stick(ingredients, sep = " and ", conj = NULL)
#> [1] "sugar and spice and everything nice"
plu::stick(ingredients, sep = "/", conj = NULL)
#> [1] "sugar/spice/everything nice"
creed <- c("snow", "rain", "heat", "gloom of night") plu::stick(creed, sep = " nor ", conj = NULL)
#> [1] "snow nor rain nor heat nor gloom of night"
# Oxford commas are only added when there are three or more elements plu::stick(letters[1:3], oxford = TRUE)
#> [1] "a, b, and c"
plu::stick(letters[1:2], oxford = TRUE)
#> [1] "a and b"
# Oxford commas are optional for English, but should be FALSE for most languages ingredientes <- c("azúcar", "flores", "muchos colores") plu::stick(ingredientes, conj = " y ", oxford = FALSE)
#> [1] "azúcar, flores y muchos colores"