-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Just an idea:
sentence_list <- function(x, period = FALSE, ...) {
n <- length(x)
rtn <- paste(c(paste(x[-n], collapse = ", "), x[n]), collapse = ", and ")
if (period) {
rtn <- paste0(rtn, ".")
}
rtn
}
# Example
x <- c("first item", "second item", "third item")
sentence_list(x, period = FALSE)
# [1] "first item, second item, and third item"
sentence_list(x, period = TRUE)
# [1] "first item, second item, and third item."