R/FSA_dir.create.R

Defines functions FSA_dir.create

Documented in FSA_dir.create

FSA_dir.create <- function(folder, allowedUnlink = FALSE) {
  dirCreationRCheck <- FALSE
  dirCreationCheck <- dir.exists(folder)
  if (allowedUnlink) {
    if (dirCreationCheck) {
      tryCatch({
        unlink(folder, recursive = TRUE)
        dirCreationCheck <- FALSE
      },
      warning = function(w) {
        dirCreationCheck <- TRUE
        dirCreationRCheck <- FALSE
        FSA_logRecorder(paste0("Can't delete `", folder, "`!"))
      },
      error = function(e) {
        dirCreationCheck <- TRUE
        dirCreationRCheck <- FALSE
        FSA_logRecorder(paste0("Can't delete `", folder, "`!"))
      })
    }
  }
  if (!dirCreationCheck) {
    tryCatch({
      dir.create(folder, recursive = TRUE)
      dirCreationRCheck <- TRUE
    },
    warning = function(w) {
      dirCreationRCheck <- FALSE
      FSA_logRecorder(paste0("Can't create `", folder, "`!"))
    },
    error = function(e) {
      dirCreationRCheck <- FALSE
      FSA_logRecorder(paste0("Can't create `", folder, "`!"))
    })
  }
  return(dirCreationRCheck)
}

Try the IDSL.FSA package in your browser

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

IDSL.FSA documentation built on July 9, 2023, 6:45 p.m.