R/compsplit.R

Defines functions compsplit

compsplit <- function(x, split) {
  
  if (split %in% gs("special.characters"))
    split <- paste0("\\", split)

  res <- strsplit(x, split)

  if (is.list(res)) {
    withspace <- any(unlist(lapply(res, grepl, pattern = "^\\s+|\\s+$")))
    res <- lapply(res, gsub, pattern = "^\\s+|\\s+$", replacement = "")
  }
  else {
    withspace <- any(grepl("^\\s+|\\s+$", "", res))
    res <- gsub("^\\s+|\\s+$", "", res)
  }
  ##
  attr(res, "withspace") <- withspace
  
  res
}

Try the meta package in your browser

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

meta documentation built on Oct. 31, 2024, 5:07 p.m.