R/strsplit0.R

Defines functions strsplit0

Documented in strsplit0

#' Split a string vector with multiple split
#'
#' @param strVec One vector whose elements are to be split.
#' @param split character vector containing regular expression(s) to use for splitting.
#' @param simplify If TRUE, returns character vector; if not, list; Default is TRUE.
#'
#' @return vector or list of split characters.
#' @export
#'
#' @examples
strsplit0 <- function(strVec, split, simplify = TRUE) {
    if (simplify == TRUE) {
        for (sp in split) {
            strVec <- strVecSplit(strVec, sp)
        }
        return(strVec)
    } else {
        strsplit0 <- list()
        for (str in strVec) {
            for (sp in split) {
                str <- strVecSplit(str, sp)
            }
            strsplit0[[length(strsplit0) + 1]] <- str
        }
        return(strsplit0)
    }
}
yanxianUCSB/yxhelper documentation built on April 20, 2020, 4:09 p.m.