Get started with psychdsish

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:

  1. Create a project skeleton with create_project_skeleton().
  2. Validate an existing project against the conventions with validator().
  3. (rarely, and mainly for testing) Delete a skeleton with delete_project_skeleton().

Creating a 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:

create_project_skeleton(project_root = "~/git/my_project")

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 /private/var/folders/45/d07jd4jn4756zs6q38rgl4xw0000gp/T/RtmpK2gEjB/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/

Validating a project

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 ─────────────────────────────────────────────────────
#> /var/folders/45/d07jd4jn4756zs6q38rgl4xw0000gp/T/RtmpK2gEjB/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).

Deleting a skeleton

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: .gitattributes, .gitignore, CITATION.cff, LICENSE, README.md, _quarto.yml, code, data, demo_project.Rproj, methods, preregistration, 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: .gitattributes, .gitignore, CITATION.cff, LICENSE, README.md, _quarto.yml, code, data, demo_project.Rproj, methods, preregistration, reports, tools
#> Protected file: /private/var/folders/45/d07jd4jn4756zs6q38rgl4xw0000gp/T/Rtmp8zN5hl/Rbuild684e7059a4f9/psychdsish/vignettes/psychdsish.Rmd

dir.exists(project)
#> [1] TRUE

Where to go next

mirror server hosted at Truenetwork, Russian Federation.