This function alows you to take a string of words and combine them into a sentance list. For example, 'apples', 'oranges', 'pears' would become 'apples, oranges, and pears'. This function uses oxford commas.

text_list(x = "", oxford = TRUE, sep = ", ", sep_last = "and ")

Arguments

x

Character strings you want in your string.

oxford

T/F: would you like to use an oxford comma? Default = TRUE

sep

string. default = ", " but "; " or " " might be what you need!

sep_last

string. default = " and " but " & " or " , " might be what you need!

Examples

text_list(c(1,2,"hello",4,"world",6))
#> [1] "1, 2, hello, 4, world, and 6"
text_list(c(1,"world"))
#> [1] "1 and world"
text_list(c(1,2,"hello",4,"world",6), oxford = FALSE)
#> [1] "1, 2, hello, 4, world and 6"
paste0("here is a list of things: ",
  text_list(paste0("list", 1:5), sep = " ", sep_last = ""))
#> [1] "here is a list of things: list1 list2 list3 list4 list5"