Skip to contents

Check 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 to dir, not just file names, so "data/*.csv" matches csv files in the data subdirectory. 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 TRUE include hidden files

recurse

If TRUE recurse fully, if a positive number the number of levels to recurse

type

File type to return, one of "file", "directory", or "any"

regex

If TRUE use files as regular expressions otherwise assume wildcard (glob) patterns

invert

If TRUE return 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 directory

  • check_allowed_files(): Check that only the allowed file(s) exist

  • check_disallowed_files(): Check if any disallowed file(s) exist

  • check_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