Check for allowed or disallowed files in a project or directory
Source:R/check_files.R
check_files.RdCheck for allowed or disallowed files in a project or directory
Usage
find_files(
files,
dir = here::here(),
all = FALSE,
recurse = TRUE,
type = c("file", "directory", "any"),
regex = FALSE,
invert = FALSE
)
check_allowed_files(
files,
dir = here::here(),
all = FALSE,
recurse = TRUE,
type = c("file", "directory", "any"),
regex = FALSE
)
check_disallowed_files(files, dir = here::here(), regex = FALSE)
check_required_files(files, dir = here::here())Arguments
- files
Character vector of file names or patterns to match (wildcards by default, regular expressions when
regex = TRUE). Patterns are matched against file paths relative todir, not just file names, so"data/*.csv"matches csv files in thedatasubdirectory. Note that*also matches/, so"*.csv"matches csv files at any depth.check_required_files()matches file names literally and does not support patterns.- dir
Directory to check
- all
If
TRUEinclude hidden files- recurse
If
TRUErecurse fully, if a positive number the number of levels to recurse- type
File type to return, one of "file", "directory", or "any"
- regex
If
TRUEusefilesas regular expressions otherwise assume wildcard (glob) patterns- invert
If
TRUEreturn files which do not match
Value
find_files() returns a character vector of matching file paths.
The check_* functions return TRUE or FALSE invisibly, indicating
whether the check passed.
Functions
find_files(): Find all files that match the given pattern (glob or regex) within the given directorycheck_allowed_files(): Check that only the allowed file(s) existcheck_disallowed_files(): Check if any disallowed file(s) existcheck_required_files(): Check that the required file(s) exist; file names are matched literally (patterns are not supported)
Examples
dir = system.file("examples/hw1", package = "checklist")
find_files("*.qmd", dir)
#> hw1.qmd
check_allowed_files(c("README.md", "hw1.qmd", "hw1.Rproj"), dir)
check_disallowed_files("hw1.md", dir)
check_required_files("hw1.pdf", dir)
#> The following required files are missing:
#> ────────────────────────────────────────────────────────────────────────────────
#> ✖ hw1.pdf