R/utils.R

Defines functions reg_match reg_fun reg_suffix file_suffix file_bare file_path

# 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/datamake documentation built on May 18, 2019, 10:23 p.m.