check_dir: Check a directory exists

View source: R/checks.R

check_dirR Documentation

Check a directory exists

Description

This function checks whether a directory exists and, if not, returns an informative error message. The inputted directory can be edited with the addition of a '/' if requested.

Usage

check_dir(arg = deparse(substitute(input)), input, check_slash = FALSE)

Arguments

arg

(optional) A character string which defines the argument of a parent function.

input

A character string which defines a directory.

check_slash

A logical input that defines whether or not to check the end of a string for '/'. If TRUE and a '/' is lacking, this is added to the returned directory.

Value

The function checks whether or not a directory exists. If so, the function returns either the directory as inputted, or the directory with a '/' added to the end. If not, the function returns an informative error message.

Author(s)

Edward Lavender

Examples

check_dir(arg = "This should work.", input = tempdir())
check_dir(arg = "Check the slash.", input = tempdir(), check_slash = TRUE)
## Not run: 
check_dir(arg = "This is silly.",
          input = ".~/this_is_a_silly_directory/")

## End(Not run)

edwardlavender/utils.add documentation built on Dec. 14, 2024, 8:11 a.m.