#' Directory check
#'
#' Check that
#' 1. The user knows that the data will not be saved if `dir = NULL`.
#' 1. The directory exists if it can be created.
#' 1. The function fails if the directory cannot be created.
#'
#' @template dir
#' @template verbose
#'
#' @author Chantel R. Wetzel
#' @export
#'
#' @examples
#' check_dir(getwd(), verbose = FALSE)
#' # See more output
#' check_dir(getwd())
#'
check_dir <- function(dir, verbose = TRUE){
if (is.null(dir) || length(dir) == 0) {
if (verbose) {
message("Output will not be saved in `dir` because dir = NULL.")
}
} else {
dir.create(dir, showWarnings = FALSE, recursive = TRUE)
if (!file.exists(dir)) {
stop(glue::glue(
"[ENOENT] Failed to make the following directory:
'{dir}'"
))
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.