R/utils.R

# UTILS

# Pattern matching & composition ----
# ===================================

reg_match = function(string, pattern)
  regmatches(string, regexpr(pattern, string))

reg_fun = function(x)
  paste0("^(.*::)*(", paste(x, collapse = "|"), ")")

reg_suffix = function(x)
  paste0("\\.(", paste(x, collapse = "|"), ")$")

# File name operations ----
# =========================

file_suffix = function(file) {
  if (inherits(file, "list"))
    file = unlist(file, use.names = F)
  reg_match(file, "[^\\.]+$")
}

file_bare = function(file) {
  if (inherits(file, "list"))
    file = unlist(file, use.names = F)
  reg_match(file, "[^/]+$")
}

file_path = function(file) {
  if (inherits(file, "list"))
    file = unlist(file, use.names = F)
  gsub("[^/]+$", "", file)
}
jchrom/dataglue documentation built on May 18, 2019, 10:22 p.m.