R/useful_string.R

Defines functions collapse_and collapse_or

collapse_and <- function(x,oxford=TRUE,ampersand=FALSE){
  if(length(x)==1){
    return(x)
  }else{
    commas <- paste(x[1:(length(x)-1)],collapse=', ')
    out <- paste(commas,x[length(x)],sep=ifelse(ampersand,ifelse(oxford,', & ',' & '), ifelse(oxford,', and ',' and ')))
    return(out)
  }
}

collapse_or <- function(x,oxford=TRUE){
  if(length(x)==1){
    return(x)
  }else{
    commas <- paste(x[1:(length(x)-1)],collapse=', ')
    out <- paste(commas,x[length(x)],sep=ifelse(oxford,', or ',' or '))
    return(out)
  }
}
statisticiansix/demonstrandum documentation built on Dec. 2, 2019, 1:29 a.m.