R/utils.R

Defines functions .vector_to_sentence

#' Convert a List to A Sentence Form
#' Vectors of 1, 2 and 3 letters become 'A', 'A and B', 'A, B and C'.
#' @noRd
.vector_to_sentence <- function(vector) {

  if (length(vector) > 1) {
    last <- vector[length(vector)]
    not_last <- vector[-length(vector)]
    sentence <- paste(paste(not_last, collapse = ", "), "and", last)
    return(sentence)
  }

  vector

}

Try the aftables package in your browser

Any scripts or data that you put into this service are public.

aftables documentation built on April 12, 2025, 9:16 a.m.