psychdsish helps you
set up and check research projects that follow a standardised,
reproducibility-friendly layout. The layout is loosely inspired by the
psych-DS data standard, but is
deliberately not fully psych-DS compliant – most notably it
drops the JSON metadata requirement. Hence psych-DS-ish.
There are three things you will usually do:
create_project_skeleton().validator().delete_project_skeleton().create_project_skeleton() writes an opinionated
directory tree together with a README, a licence, a
.gitignore with sensible defaults, and Quarto templates for
processing and analysis code.
If you know the path to your project you can call it directly from the console:
There is no default project_root, so files are only
written where you say. From the tools/project_creator.qmd
file that the skeleton creates, use project_root = "../" to
write to the project root one level up.
Here is a complete, self-contained round-trip inside a temporary directory:
project <- file.path(tempdir(), "demo_project")
create_project_skeleton(project_root = project, overwrite = TRUE)
#> Created 20, overwrote 0, and skipped 0 existing files in /tmp/Rtmp5cW4Jp/demo_project.
# the top-level layout that was created
list.dirs(project, recursive = FALSE, full.names = FALSE)
#> [1] "code" "data" "methods" "preregistration"
#> [5] "reports" "tools"The skeleton separates raw data, processed data, analysis code, outputs, and documentation:
my_project/
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── code/
│ ├── analysis.qmd
│ └── processing.qmd
├── data/
│ ├── outputs/
│ │ ├── fitted_models/
│ │ ├── plots/
│ │ └── results/
│ ├── processed/
│ └── raw/
├── methods/
├── preregistration/
└── reports/
validator() checks a project against the psych-DS-ish
conventions and returns a table of tests, each marked PASS,
FAIL, or SKIP (the check could not be run),
with guidance on how to fix any failures. A freshly created skeleton
fails only one test, as a reminder to replace the template text in its
README.md. Four tests are skipped: the raw data check,
because the project is not yet a git repository; the rendered
.html check, because nothing has been rendered; and the two
codebook checks, because there is no processed data yet:
res <- validator(project_root = project)
res
#> ── psych-DS-ish validation ─────────────────────────────────────────────────────
#> /tmp/Rtmp5cW4Jp/demo_project
#> Layout: single study
#> ✖ FAIL README has been customised (no template placeholders)
#> Replace the template text in README.md: '# Project Title'; 'Add aims, data sources, and reproduction steps.'; 'Authors (Year). Title. URL.'
#> ◯ SKIP Codebooks are completed (no 'TO BE COMPLETED MANUALLY')
#> No data files under data/.
#> ◯ SKIP Data files are documented in dataset_description.json (psych-DS)
#> No data files under data/.
#> ◯ SKIP Every data file has a codebook
#> No data files under data/.
#> ◯ SKIP Processed data file names follow the psych-DS convention
#> No data files under data/.
#> ◯ SKIP Raw data unchanged since first committed (git)
#> Not a git repository (or git is not installed), so the history of data/raw/ cannot be checked.
#> ◯ SKIP Rendered .html files are up to date with their .qmd
#> No rendered .html files found next to .qmd files.
#> ✔ PASS All .qmd files reside in code, tools
#> ✔ PASS Directory exists: code
#> ✔ PASS Directory exists: data
#> ✔ PASS Directory exists: data/outputs
#> ✔ PASS Directory exists: data/outputs/fitted_models
#> ✔ PASS Directory exists: data/outputs/plots
#> ✔ PASS Directory exists: data/outputs/results
#> ✔ PASS Directory exists: data/processed
#> ✔ PASS Directory exists: data/raw
#> ✔ PASS Directory exists: methods
#> ✔ PASS Directory exists: preregistration
#> ✔ PASS Directory exists: reports
#> ✔ PASS File exists: licence/license
#> ✔ PASS File exists: readme.md
#> ✔ PASS Has .gitignore
#> ✔ PASS License name is canonical (LICENSE)
#> ✔ PASS No .R files present (as expected)
#> ✔ PASS No .Rmd files present (as expected)
#> ✔ PASS No .csv files present (as expected)
#> ✔ PASS No .docx files present (as expected)
#> ✔ PASS No .dta files present (as expected)
#> ✔ PASS No .feather files present (as expected)
#> ✔ PASS No .pdf files present (as expected)
#> ✔ PASS No .png files present (as expected)
#> ✔ PASS No .rds files present (as expected)
#> ✔ PASS No .sav files present (as expected)
#> ✔ PASS No .tsv files present (as expected)
#> ✔ PASS No .xlsx files present (as expected)
#> ✔ PASS No absolute file paths in code
#> ✔ PASS No data files stored under code
#> ✔ PASS No setwd() calls in code
#> ✔ PASS No spaces in filenames
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 of 33 checks failed. (6 skipped)The rules cover, among other things, which directories must exist,
where each file type is allowed to live (for example, data files under
data/, scripts under code/ or
tools/), that filenames contain no spaces, that raw data
have not changed since they were first committed to git, that rendered
.html files are up to date, that code contains no
setwd() calls or absolute paths, and that every processed
data file has a completed codebook. See ?validator for the
full set of rules.
To fail a continuous integration job (e.g., GitHub Actions) when any
check fails, use validator(strict = TRUE).
delete_project_skeleton() exists mainly for testing. It
is deliberately cautious: by default it requires interactive
confirmation and the presence of a “sentinel” file (such as
.gitignore) so that you cannot point it at an arbitrary
directory by accident. Always preview with dry_run = TRUE
first.
# preview only -- nothing is removed
invisible(delete_project_skeleton(project_root = project, confirm = FALSE, dry_run = TRUE))
#> Dry run: would delete 32 items: _quarto.yml, .gitattributes, .gitignore, CITATION.cff, code, data, demo_project.Rproj, LICENSE, methods, preregistration, README.md, reports, tools
#> No files deleted. Set `dry_run = FALSE` to execute.
# actually remove the demo project (non-interactive)
delete_project_skeleton(project_root = project, confirm = FALSE)
#> Deleted: _quarto.yml, .gitattributes, .gitignore, CITATION.cff, code, data, demo_project.Rproj, LICENSE, methods, preregistration, README.md, reports, tools
#> Protected file: /tmp/RtmpB42N6A/Rbuildde37922c5e5/psychdsish/vignettes/psychdsish.Rmd
dir.exists(project)
#> [1] TRUE?create_project_skeleton for every directory and
template that is created.?validator for the complete list of validation
rules.style_all_files(), poorly_styled_code()) and
for spotting unused dependencies and objects
(check_unused_dependencies(),
check_unused_objects()).