| validator | R Documentation |
This function checks whether a project directory follows a defined set
of structural and file-placement rules. The layout is loosely inspired by the
psych-DS specification, but is not
fully psych-DS compliant. It adds extra conventions for reproducibility
and common analysis workflows, including Quarto file templates and
a .gitignore file. It does not comply with psych-ds's .json requirement.
validator(
project_root = "../",
exclude_dirs = c("renv", "packrat", "_site", "_book", "_freeze", "node_modules"),
strict = FALSE
)
project_root |
Character scalar. Path to the project root directory.
Defaults to |
exclude_dirs |
Character vector of directory names whose contents are
ignored, in addition to all hidden directories (those whose name starts
with a dot, e.g., |
strict |
Logical. If |
The project's layout is detected from its folders: multi-study "by study"
if there are study_1/, study_2/, etc. folders at the project root,
multi-study "by type" if there are such folders inside code/,
data/raw/, etc., and single-study otherwise (see
create_project_skeleton()). The checks below are applied to each study's
folders. In multi-study projects, .qmd, .Rmd, and .R files for
analyses that combine studies may also be placed in a root-level code/
folder (by study) or anywhere in code/ (by type).
The validator performs several categories of checks:
Required directories — Ensures that expected top-level and
nested folders exist (e.g., code/, data/raw/, methods/).
Required files — Confirms presence of a readme.md and
a license file (e.g., LICENSE).
Filetype-location constraints — Ensures specific file types
(e.g., .qmd, .csv, .rds, .png) only appear in approved
subdirectories and not elsewhere in the project.
Special HTML rule — All .html files must be under code/
or methods/.
Hygiene checks — Optional rules that discourage spaces in
filenames, check for .gitignore presence, and prevent data
files being stored under code/.
Reproducibility checks — Raw data files have not been modified
or deleted since they were first committed to git (including
uncommitted changes); rendered .html files are newer than their
.qmd (using git commit times for committed, unmodified files, and
file modification times otherwise); README.md no longer contains
the template placeholders written by create_project_skeleton();
and R code in .R files and in .qmd/.Rmd code chunks contains
no setwd() calls or absolute file paths (e.g., "~/",
"/Users/", "C:/"). Comment lines are ignored.
Codebook checks — Every data file under data/ is documented,
by a codebook named after it (e.g.,
study-1_stage-processed_data.csv ->
study-1_stage-processed_codebook.csv, any data file extension),
a psych-DS sidecar (study-1_stage-processed_data.json), or its
columns being listed in dataset_description.json. .csv/.tsv
codebooks no longer contain the "TO BE COMPLETED MANUALLY"
placeholders written by the codebook chunk in
code/processing.qmd. Undocumented raw data is a warning rather
than a failure.
psych-DS checks (reported as "WARN") — Data file names follow
the psych-DS convention of key-value pairs ending in _data
(leniently for raw data, which often cannot be renamed); data files
are described in dataset_description.json rather than only in a
.csv/.xlsx codebook (see write_dataset_description()); and
every codebook or .json under data/ can be matched to the data
file it describes.
Checks that cannot be run are reported as "SKIP" rather than "PASS",
e.g., the raw data check when the project is not a git repository, or the
.html check when nothing has been rendered yet. Checks that are worth
acting on but are not failures, such as a project that works but is not
fully psych-DS compliant, are reported as "WARN". Neither causes
strict = TRUE to fail.
A tibble of class psychdsish_validation with one row per check
(failures first, then warnings and skipped checks), containing:
Description of the check performed.
"PASS", "FAIL", "WARN" (worth fixing, but not a
failure), or "SKIP" (the check could not be run).
Additional information, such as instructions for fixing failures or offending file paths.
Printing it shows coloured PASS/FAIL results with guidance for failures.
summary() returns a list with project_root, layout ("single",
"by_study", or "by_type"), studies (the study folder names),
n_pass, n_fail, n_warn, n_skip, and passed (TRUE if no check
failed). If strict = TRUE and any check
fails, an error is thrown instead.
project <- file.path(tempdir(), "my_project")
create_project_skeleton(project, quiet = TRUE)
# Validate the project and print the results
results <- validator(project)
results
# Overall result
summary(results)$passed
# Throw an error if any check fails, e.g., to fail a GitHub Actions job
try(validator(project, strict = TRUE))
# Display the results as a table, e.g., in a Quarto report
if (requireNamespace("knitr", quietly = TRUE)) {
knitr::kable(results)
}
unlink(project, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.