R/makeSentence.R

#' Make Sentance
#'
#' Compress atomic vector into a sentence.
#' @param x Atomic vector
#' @export
#' @return Sentence
#' @examples
#' makeSentence(x = c('red', 'yellow', 'blue'))


makeSentence <- function(x){
  if (length(x) == 1){
    return(x)
  }else if (length(x) == 2){
    return(paste(x, collapse = ' and '))
  }else{
    return(
      paste0(
        paste(saxy::allbutlast(x), collapse = ', '),
        paste0(', and ', saxy::last(x))
      )
    )
  }
}
ssaxe-usgs/saxey documentation built on May 25, 2019, 5:02 a.m.