R/helpers.R

Defines functions path2name remove_ext name2path create_if_needed

create_if_needed <- function(path, ...) {
  if (!dir.exists(path)) {
    dir.create(path, ...)
  }
}

name2path <- function(dir, name, ext) {
  file.path(dir, paste0(name, ext))
}

remove_ext <- function(filename) {
  gsub(pattern = "(.+)\\.([^\\.]+)",
       replacement = "\\1",
       filename)
}

path2name <- function(path) {
  remove_ext(basename(path))
}
antoine-sachet/customFunctions documentation built on Sept. 25, 2020, 8:56 p.m.