R/dir_new.R

Defines functions new_dir dir_new

new_dir <- function(..., create = TRUE, safe = TRUE)
{
    path <- file.path(...)

    if (nchar(file_ext(path)) > 0L) {
        stop("'path' points to a specific file, ",
             "not to a directory.", call. = FALSE)
    }

    if (create && safe && !dir.exists(dirname(path))) {
        stop("'safe' is TRUE but multiple dirs in 'path' must be created.",
             call. = FALSE)
    }

    structure(
        path,
        created = if (create) dir.create(path, FALSE, !safe) else FALSE,
        exists  = dir.exists(path),
        class   = "dir")
}

dir_new <- function(...) new_dir(...)
jeanmathieupotvin/dfp documentation built on Jan. 8, 2020, 2:32 a.m.