Learn R Programming

pretestcad (version 1.1.0)

oxford_comma: Character Vector To List Phrase With Oxford Comma

Description

A function that converts a character vector into a list phrase that uses the Oxford comma.

Usage

oxford_comma(chr, sep = ", ", final = "or")

Value

A string in the form of a list that has a comma if there are at least three elements in the list (e.g. "a, b, or c")

Arguments

chr

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

sep

Separator symbols used to separate the elements in the character vector, Default: ', '

final

String to use in place of the final separator when we have at least two elements in the character vector, Default: 'or'.

Examples

Run this code
oxford_comma(c("James", "John", "Jeremy"))

oxford_comma(c("James", "John", "Jeremy"), final = "and")

oxford_comma(c("James", "John"))

oxford_comma(c("James"))

Run the code above in your browser using DataLab