Learn R Programming

xfun (version 0.50)

join_words: 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
)

Value

A character string marked by raw_string().

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.

Examples

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

Run the code above in your browser using DataLab