Skip to contents

Convert a list or vector to text with human-readable separators, e.g., "A, B & C".

Usage

comma_and(x, comma = ", ", and = " & ", oxford = FALSE)

Arguments

x

The list or vector to convert

comma

The text to use to separate all but the last item

and

The text to use to separate the last item

oxford

Whether to use an oxford comma before the last item

Value

A character string

Examples

comma_and(LETTERS[1:5])
#> [1] "A, B, C, D & E"
comma_and(LETTERS[1:5], and = " and ")
#> [1] "A, B, C, D and E"
comma_and(LETTERS[1:5], comma = "; ")
#> [1] "A; B; C; D & E"

# change and to use an oxford comma
my_list <- list("Nelson Mandela",
                "an 800-year-old demigod",
                "a dildo collector")
comma_and(my_list) # probably not what you mean
#> [1] "Nelson Mandela, an 800-year-old demigod & a dildo collector"
comma_and(my_list, oxford = TRUE)
#> [1] "Nelson Mandela, an 800-year-old demigod, & a dildo collector"