Skip to contents

Turn vectors into lists with any specified linking word

Usage

listify(items, linking_word = "and", oxford_comma = FALSE)

Arguments

items

A vector of items to turn into a list phrase (e.g. c("a", "b", "c")).

linking_word

Defaults to "and". Can be anything.

oxford_comma

logical. Defaults to FALSE. If TRUE, an oxford comma is added (e.g. "a, b, and c"). This also applies to lists of two items, which is useful when nesting lists (e.g. "a, b or c, and d").

Value

A string in the form of a list (e.g. "a, b and c")

See also

Examples

listify(c("a", "b", "c"), "or")
#> [1] "a, b or c"
listify(c("a", "b", "c"), oxford_comma = TRUE)
#> [1] "a, b, and c"