Write out a list of words

write_out(word_list, quoted = FALSE, human = TRUE,
  separator = ifelse(sum(grepl(",", word_list)), ";", ","),
  placement = ifelse(human & grepl("United States", Sys.getlocale()),
  "US", "international"), oxford = TRUE, quote_type = c("double",
  "single"), curly = human, collapse = c("and", "&", "+", "or",
  "and/or"), ending = c("", ".", ","))

Arguments

word_list

Character vector. Words to be listed out.

quoted

Logical. If TRUE, will wrap each word in quotation marks.

human

Logical. If FALSE, will leave out the final conjunction.

separator

Character. What punctuation do you want between elements? Defaults to semicolon if any element contains a comma, comma otherwise.

placement

Character. If "US", will place commas and periods inside any quotation marks (and other punctuation outside them). If "international", will place all punctuation outside quotation marks. Defaults to "US" if Sys.getlocale places you in the US and human is set to TRUE.

oxford

Logical. Use an Oxford comma? Defaults to TRUE. Parameter is ignored if separator is not a comma.

quote_type

Character. "double" for double quotes, "single" for single.

curly

Logical. TRUE for Unicode curly quotes, FALSE for straight ASCII quotes. Defaults to FALSE if human == FALSE, TRUE otherwise.

collapse

Character. What final conjunction or sign do you want? "and", an ampersand, a plus sign, an "or", an "and/or"...?

ending

Character (e.g. period, comma, or zero-length string). What character if any do you need inside the final quotation mark, or at the end of the function"s output?

Value

Character. A pretty, human-readable list.

Examples

write_out("apples")
#> [1] "apples"
write_out(c("apples", "oranges"))
#> [1] "apples and oranges"
write_out(c("apples", "oranges"), quoted = TRUE)
#> [1] "“apples” and “oranges”"
write_out( c("hello, my friend", "welcome", "enter"), quoted = TRUE, ending = "." )
#> [1] "“hello, my friend”; “welcome”; and “enter.”"
write_out(c("apples", "oranges"), quoted = TRUE, quote_type = "single")
#> [1] "‘apples’ and ‘oranges’"
write_out( c("apples", "oranges"), quoted = TRUE, quote_type = "single", curly = FALSE )
#> [1] "'apples' and 'oranges'"
write_out(c("apples", "oranges", "bananas"))
#> [1] "apples, oranges, and bananas"
write_out(c("apples", "oranges", "bananas"), quoted = TRUE, ending = ".")
#> [1] "“apples,” “oranges,” and “bananas.”"
write_out(c("apples", "oranges", "bananas"), oxford = FALSE)
#> [1] "apples, oranges and bananas"
write_out(c("apples", "oranges", "bananas"), collapse = "or")
#> [1] "apples, oranges, or bananas"
write_out(c("apples", "oranges", "bananas"), human = FALSE)
#> [1] "apples, oranges, bananas"
write_out(character(0))
#> character(0)