join_words: Join multiple words into a single string

View source: R/string.R

join_wordsR Documentation

Join multiple words into a single string

Description

If words is of length 2, the first word and second word are joined by the and string; if and is blank, sep is used. When the length is greater than 2, sep is used to separate all words, and the and string is prepended to the last word.

Usage

join_words(
  words,
  sep = ", ",
  and = " and ",
  before = "",
  after = before,
  oxford_comma = TRUE
)

Arguments

words

A character vector.

sep

Separator to be inserted between words.

and

Character string to be prepended to the last word.

before, after

A character string to be added before/after each word.

oxford_comma

Whether to insert the separator between the last two elements in the list.

Value

A character string marked by raw_string().

Examples

join_words("a")
join_words(c("a", "b"))
join_words(c("a", "b", "c"))
join_words(c("a", "b", "c"), sep = " / ", and = "")
join_words(c("a", "b", "c"), and = "")
join_words(c("a", "b", "c"), before = "\"", after = "\"")
join_words(c("a", "b", "c"), before = "\"", after = "\"", oxford_comma = FALSE)

xfun documentation built on April 3, 2025, 7:04 p.m.