Skip to content

Feature: sentence_<something>(x, ...) #103

@dewittpe

Description

@dewittpe

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."

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions