R/check_empty_beastier_folder.R

Defines functions check_empty_beastier_folder

Documented in check_empty_beastier_folder

#' Check there are no files in the default \link{beastier} folder
#'
#' Check there are no files in the default \link{beastier} folder.
#' The goal is to make sure no temporary files are left undeleted.
#' Will \link{stop} if there are files in the \link{beastier} folder
#' @inheritParams default_params_doc
#' @return Nothing.
#' Will \link{stop} if there are files in the \link{beastier} folder
#' @author Richèl J.C. Bilderbeek
#' @export
check_empty_beastier_folder <- function(
  beastier_folder = get_beastier_folder()
) {
  dirs <- normalizePath(list.dirs(beastier_folder))
  dirs <- dirs[dirs != normalizePath(beastier_folder, mustWork = FALSE)]

  if (length(dirs) != 0) {
    stop(
      "Folders found in beastier folder. \n",
      "beastier_folder: ", beastier_folder, " \n",
      "length(list.dirs(beastier_folder)): ", length(dirs), " \n",
      "head(list.dirs(beastier_folder)): ",
        paste(utils::head(dirs), collapse = ",")
    )
  }
  filenames <- list.files(beastier_folder, full.names = TRUE, recursive = TRUE)
  if (length(filenames) != 0) {
    stop(
      "Files found in beastier folder. \n",
      "beastier_folder: ", beastier_folder, " \n",
      "length(list.files(beastier_folder))): ", length(filenames), " \n",
      "head(list.files(beastier_folder)): ",
        paste(utils::head(filenames), collapse = ",")
    )
  }
}

Try the beastier package in your browser

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

beastier documentation built on Sept. 19, 2021, 5:06 p.m.