Package {psychdsish}


Title: Keep Data, R Code, and Outputs Organized and Reproducible
Version: 0.2.3
Description: Creates a standardised project skeleton for research projects in R that is loosely inspired by the 'psych-DS' data standard (https://psych-ds.github.io/) for psychological data, and checks whether an existing project follows the same conventions. The layout is not fully 'psych-DS' compliant – most notably the 'dataset_description.json' metadata file is optional rather than required, and can be generated from the 'codebook' files – hence 'psych-DS-ish'. Single- and multi-study projects are supported. Alongside the directory structure it generates 'Quarto' templates for processing and analysis code (including a 'codebook' for the processed data), a 'README', a licence, a citation file, a '.gitignore' with sensible defaults, and a 'Quarto' project file that renders the code in order. A 'validator' function reports whether a project follows the conventions, including whether raw data have changed since they were first committed to 'Git' and whether rendered reports are up to date, and, where it does not, how to fix it. 'RStudio' users can create projects from the New Project wizard and validate them from the 'Addins' menu. See 'Hussey' (2026) <doi:10.5281/zenodo.21441984> for the archived software record.
URL: https://github.com/ianhussey/psychdsish
BugReports: https://github.com/ianhussey/psychdsish/issues
License: MIT + file LICENSE
Encoding: UTF-8
SystemRequirements: Quarto command line tools (<https://quarto.org>) for rendering projects and check_unused_dependencies(); Git (<https://git-scm.com>) for the raw data check in validator() (both optional)
Language: en-US
RoxygenNote: 7.3.2
Depends: R (≥ 4.1)
Imports: cli, dplyr, fs, jsonlite, purrr, quarto, rmarkdown, stats, stringr, styler, tibble, utils
Suggests: covr, knitr, kableExtra, rstudioapi, spelling, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-11-08 11:56:33 UTC; Ian-Hussey
Author: Ian Hussey ORCID iD [aut, cre, cph]
Maintainer: Ian Hussey <ian.hussey@unibe.ch>
Repository: CRAN
Date/Publication: 2026-11-29 11:30:02 UTC

psychdsish: Keep Data, R Code, and Outputs Organized and Reproducible

Description

logo

Creates a standardised project skeleton for research projects in R that is loosely inspired by the 'psych-DS' data standard (https://psych-ds.github.io/) for psychological data, and checks whether an existing project follows the same conventions. The layout is not fully 'psych-DS' compliant – most notably the 'dataset_description.json' metadata file is optional rather than required, and can be generated from the 'codebook' files – hence 'psych-DS-ish'. Single- and multi-study projects are supported. Alongside the directory structure it generates 'Quarto' templates for processing and analysis code (including a 'codebook' for the processed data), a 'README', a licence, a citation file, a '.gitignore' with sensible defaults, and a 'Quarto' project file that renders the code in order. A 'validator' function reports whether a project follows the conventions, including whether raw data have changed since they were first committed to 'Git' and whether rendered reports are up to date, and, where it does not, how to fix it. 'RStudio' users can create projects from the New Project wizard and validate them from the 'Addins' menu. See 'Hussey' (2026) doi:10.5281/zenodo.21441984 for the archived software record.

Author(s)

Maintainer: Ian Hussey ian.hussey@unibe.ch (ORCID) [copyright holder]

See Also

Useful links:


Scan a project for possibly-unused packages across all QMD/RMD files

Description

Recursively finds .qmd and .Rmd files under root, renders each with unused_dependencies() (which tries Quarto first and falls back to R Markdown), and returns a single tibble with a file column and the detected possibly_unused_packages.

Usage

check_unused_dependencies(root = ".")

Arguments

root

Directory to scan (default ".").

Value

A tibble with columns:

Examples


# Renders each document, so requires the Quarto command line tools
if (!is.null(quarto::quarto_path())) {
  project <- file.path(tempdir(), "unused_dependencies_demo")
  dir.create(project)
  writeLines(
    c(
      "---",
      "title: Demo",
      "---",
      "",
      "```{r}",
      "library(tools) # attached but never used",
      "x <- mean(1:10)",
      "```"
    ),
    file.path(project, "analysis.qmd")
  )
  print(check_unused_dependencies(project))
  unlink(project, recursive = TRUE)
}



Check all project files for objects that are created but never used

Description

Recursively searches for R/Quarto files and applies check_unused_objects_single_file() to each, collating results.

Usage

check_unused_objects(
  root = ".",
  patterns = c("\\.R$", "\\.r$", "\\.Rmd$", "\\.rmd$", "\\.qmd$", "\\.Qmd$"),
  exclude_dirs = c(".git", "renv", "_site", "_freeze", ".quarto", "_book", "tools"),
  verbose = FALSE
)

Arguments

root

Character scalar. Directory to search from (default ".").

patterns

Character vector of regexes for file extensions to include. Defaults to common R and Quarto suffixes.

exclude_dirs

Character vector of directory names to skip anywhere in the path (default: c(".git","renv","_site","_freeze",".quarto","_book","tools")).

verbose

Logical; if TRUE, message progress (default FALSE).

Details

Supported extensions: .R, .r, .Rmd, .rmd, .qmd, .Qmd.

Value

A data frame with columns:

file

File path (character).

unused_objects

Name of an object that is created but never used (character).

One row per unused object. If none are found, returns an empty data frame with the two columns.

Examples

project <- file.path(tempdir(), "unused_objects_demo")
dir.create(project)
writeLines(
  c(
    "df1 <- data.frame(x = 1:3)",
    "df2 <- transform(df1, y = x * 2) # never used",
    "print(df1)"
  ),
  file.path(project, "analysis.R")
)
check_unused_objects(project)
unlink(project, recursive = TRUE)


Check for objects that are created but never used within a file

Description

Parses an R script or an R/Quarto document, extracts the R code, and reports symbols that are assigned to but never referenced anywhere else in the same file. Supports .R, .Rmd, and .qmd (R code chunks only for the latter two).

Usage

check_unused_objects_single_file(path)

Arguments

path

Character. Path to a file.

Value

A data frame with one column, unused_objects, listing orphaned objects. Returns an empty data frame if no orphans are found.

Examples

path <- tempfile(fileext = ".R")
writeLines(
  c(
    "df1 <- data.frame(x = 1:3)",
    "df2 <- transform(df1, y = x * 2) # never used",
    "print(df1)"
  ),
  path
)
check_unused_objects_single_file(path)
unlink(path)


Create an opinionated project directory skeleton following psych-ds-ish standard

Description

This function creates a standardised-ish directory and file structure for a research project. 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.

Usage

create_project_skeleton(
  project_root,
  overwrite = FALSE,
  rproj = TRUE,
  quarto_yml = TRUE,
  studies = 1,
  layout = c("by_study", "by_type"),
  quiet = FALSE
)

Arguments

project_root

Character scalar. Path to the root directory where the project skeleton should be created, e.g., "~/git/my_project" from the console, or "../" from tools/project_creator.qmd in the project. There is no default, so that files are only written where you say.

overwrite

Logical. If TRUE, existing files will be overwritten. Defaults to FALSE.

rproj

Logical. If TRUE (default), an RStudio project file named after the project root directory (e.g., my_project.Rproj) is created, unless the project root already contains an .Rproj file.

quarto_yml

Logical. If TRUE (default), a ⁠_quarto.yml⁠ file is created that makes the project a Quarto project, so that rendering the project renders code/processing.qmd and then code/analysis.qmd.

studies

Whole number. The number of studies in the project. Defaults to 1, a single-study project. With more than one study, each study gets its own ⁠code/⁠, ⁠data/⁠, ⁠methods/⁠, and ⁠preregistration/⁠ folders, arranged according to layout.

layout

Character. How a multi-study project is arranged (ignored if studies = 1):

  • "by_study" (default): one folder per study at the project root, each with the single-study structure, e.g., study_1/code/processing.qmd and ⁠study_1/data/raw/⁠. Paths in the code are the same as in a single-study project (e.g., ⁠../data/raw/⁠).

  • "by_type": one subfolder per study inside each folder, e.g., code/study_1/processing.qmd and ⁠data/raw/study_1/⁠. Paths in the code gain a level (e.g., ⁠../../data/raw/study_1/⁠).

In both layouts, ⁠reports/⁠ and ⁠tools/⁠ are shared by all studies at the project root. Re-running with a larger studies adds the new studies' folders and .qmd files without changing existing files.

quiet

Logical. If FALSE (default), a one-line summary of what was created, overwritten, or skipped is printed as a message.

Details

The created structure is designed to separate raw data, processed data, analysis code, outputs, and documentation, while including sensible defaults for licensing, reproducibility, and version control.

The following directories are created (if not already present):

Directories that would otherwise be empty receive an empty .gitkeep file so that they are tracked by Git.

The following files are created (if not already present):

Quarto .qmd files are pre-filled with:

Value

(Invisibly) a data.frame with one row per directory or file the function handled, containing:

path

Path relative to project_root.

type

Either "dir" or "file".

status

"created" if it did not exist, "overwritten" if it existed and overwrite = TRUE, "skipped" if a file existed and overwrite = FALSE, or "exists" if a directory already existed.

See Also

psych-DS specification

Examples

# These examples write to a temporary folder; use your project's path instead,
# e.g., create_project_skeleton("~/git/my_project")
project <- file.path(tempdir(), "my_project")
create_project_skeleton(project)
list.files(project, all.files = TRUE)

# Running it again skips existing files, unless overwrite = TRUE
create_project_skeleton(project)

# A project with two studies, one folder per study (study_1/code/, ...)
two_studies <- file.path(tempdir(), "two_studies")
create_project_skeleton(two_studies, studies = 2)

# The same, with one subfolder per study inside each folder (code/study_1/, ...)
by_type <- file.path(tempdir(), "two_studies_by_type")
create_project_skeleton(by_type, studies = 2, layout = "by_type")

unlink(c(project, two_studies, by_type), recursive = TRUE)


Create a psych-DS-ish project from the RStudio New Project wizard

Description

Binding for the RStudio project template, so that File > New Project > New Directory > psych-DS-ish Project creates a project skeleton with create_project_skeleton(). It is not intended to be called directly; use create_project_skeleton() instead.

Usage

create_psychdsish_project(
  path,
  quarto_yml = TRUE,
  studies = "1",
  layout = "by_study",
  ...
)

Arguments

path

Character scalar. Path to the new project directory, supplied by RStudio.

quarto_yml

Logical. Passed to create_project_skeleton(). Set by the checkbox in the New Project wizard.

studies

Number of studies, as text from the New Project wizard. Passed to create_project_skeleton().

layout

Multi-study layout, "by_study" or "by_type". Passed to create_project_skeleton().

...

Other inputs from the New Project wizard (ignored).

Value

(Invisibly) the data.frame returned by create_project_skeleton().

Examples

# What RStudio runs for a new two-study project
project <- file.path(tempdir(), "wizard_project")
create_psychdsish_project(project, studies = "2")
list.files(project)
unlink(project, recursive = TRUE)


Delete a project skeleton while protecting the running file

Description

This function deletes the contents of a project folder, but protects the file from which it is being executed (and the minimal set of ancestor directories required to keep that file). It is intended for cleaning out automatically generated project skeletons while leaving the active script or Quarto/Rmd file intact.

Usage

delete_project_skeleton(
  project_root,
  require_sentinel = TRUE,
  sentinel_names = c(".ok-to-prune", ".git", ".gitignore", ".here", "_project.yml",
    "_quarto.yml"),
  confirm = TRUE,
  dry_run = FALSE,
  large_n_warn = 10000,
  keep_file = NULL
)

Arguments

project_root

Path to the project folder whose contents should be deleted, e.g., "../" from tools/project_creator.qmd in the project. There is no default, so that nothing is deleted unless you name the folder.

require_sentinel

Logical. If TRUE (default), at least one of the files listed in sentinel_names must exist in the project root, otherwise the function aborts.

sentinel_names

Character vector of sentinel filenames checked when require_sentinel = TRUE. Defaults include .ok-to-prune, .git, .here, ⁠_project.yml⁠, and ⁠_quarto.yml⁠.

confirm

Logical. If TRUE (default), asks the user to confirm the deletion interactively by typing the folder name. In non-interactive sessions this must be set to FALSE to proceed.

dry_run

Logical. If TRUE, only reports what would be deleted without actually deleting files. Default is FALSE.

large_n_warn

Integer. Threshold number of items that triggers an additional confirmation prompt. Default is 10000.

keep_file

Path to the file to protect, or NULL (default) to detect the file the function is being called from. Supply it to run the function from the console or a script whose location cannot be detected. It must exist; if it is outside project_root, nothing is protected.

Details

Several safety mechanisms are built in to reduce the risk of catastrophic deletion:

As an additional safeguard, unless keep_file is supplied, the function must be able to identify the file it is being called from (via knitr/Quarto, RStudio, or ⁠Rscript --file=⁠) so that it never deletes the running script or its parent directories. It is therefore intended to be run from a script such as tools/project_creator.qmd, and it aborts if the current file cannot be determined.

A dry run (dry_run = TRUE) does not ask for confirmation, because it deletes nothing.

Value

Invisibly, a list with project_root, keep_file, paths (the top-level paths deleted, or that would be deleted if dry_run = TRUE, relative to project_root), and n_items (the number of files and directories they contain, including themselves).

Warning

Deletion is irreversible. Always test with dry_run = TRUE first, and keep require_sentinel = TRUE and confirm = TRUE for normal use.

Examples

project <- file.path(tempdir(), "my_project")
create_project_skeleton(project, quiet = TRUE)
keep <- file.path(project, "tools", "project_creator.qmd")

# Preview what would be deleted
delete_project_skeleton(project, keep_file = keep, dry_run = TRUE)

# Delete everything except `keep`. confirm = FALSE skips the typed
# confirmation: only use it when you are sure.
delete_project_skeleton(project, keep_file = keep, confirm = FALSE)
list.files(project, recursive = TRUE)

# From a script inside the project (e.g., tools/project_creator.qmd), the
# running file is detected and protected, so `keep_file` is not needed:
# delete_project_skeleton(project_root = "../")

unlink(project, recursive = TRUE)


A deliberately poorly styled tidyverse code example

Description

Returns a long chunk of R/tidyverse code that has intentionally inconsistent formatting, spacing, and indentation. It is designed for use in demonstrations of code style tools such as styler::style_text() or styler::style_file().

Usage

poorly_styled_code()

Details

The code:

The output is meant to provide an example input for automatic code formatting tools, so that users can compare the before (poor style) and after (styled) versions. The code is only returned, never run.

Value

A character vector of class psychdsish_code, with one element per line of code. Printing it shows the code in the console; it can be passed directly to styler::style_text() or written to a file with writeLines().

See Also

styler::style_text(), styler::style_file()

Examples

# Show the messy code
code <- poorly_styled_code()
code

# Pass it to styler to see how formatting improves
styler::style_text(code)


Style All Code in R, R Markdown, and Quarto Files in a Project

Description

Recursively finds .R, .Rmd, and .qmd files under a directory and restyles them using styler::style_file(). This includes both code scripts and R code chunks embedded in R Markdown or Quarto documents. Certain directories can be excluded from the search.

Usage

style_all_files(
  root,
  patterns = c("\\.R$", "\\.r$", "\\.Rmd$", "\\.rmd$", "\\.qmd$", "\\.Qmd$"),
  exclude_dirs = c(".git", "renv", "_site", "_freeze", ".quarto", "_book", "tools"),
  dry_run = FALSE,
  ...
)

Arguments

root

Character scalar. Path to the root directory to search. There is no default, because the files found are rewritten: from tools/style_all_files.qmd in a project, use "../".

patterns

Character vector of regular expressions for file extensions to include. Defaults to common R and Quarto file suffixes.

exclude_dirs

Character vector of directory names to skip (default: .git, renv, ⁠_site⁠, ⁠_freeze⁠, .quarto, ⁠_book⁠, tools). Matching is done anywhere in the path.

dry_run

Logical. If TRUE, returns the list of files that would be styled but does not modify them (default: FALSE).

...

Additional arguments passed on to styler::style_file(), such as strict = FALSE.

Details

Value

Invisibly returns the vector of file paths that were styled. If dry_run = TRUE, returns the vector of candidate file paths without styling.

See Also

styler::style_file(), styler::style_dir(), usethis::use_tidy_style()

Examples

project <- file.path(tempdir(), "style_demo")
dir.create(project)
writeLines("x<-c(1,2 ,3)", file.path(project, "messy.R"))

# Preview which files would be styled
style_all_files(project, dry_run = TRUE)

# Style them
style_all_files(project)
readLines(file.path(project, "messy.R"))

unlink(project, recursive = TRUE)


Validate a project directory structure against psych-ds-ish requirements

Description

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.

Usage

validator(
  project_root = "../",
  exclude_dirs = c("renv", "packrat", "_site", "_book", "_freeze", "node_modules"),
  strict = FALSE
)

Arguments

project_root

Character scalar. Path to the project root directory. Defaults to "../". The path is normalized internally.

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., ⁠.git/⁠ and ⁠.Rproj.user/⁠). Defaults to the directories generated by 'renv', 'packrat', 'Quarto', and 'Node.js'. Hidden files at the project root, such as .gitignore, are still checked.

strict

Logical. If TRUE, throw an error when any check fails, listing the failed checks and how to fix them. Useful in continuous integration (e.g., GitHub Actions), where the error makes the job fail. Defaults to FALSE.

Details

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:

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.

Value

A tibble of class psychdsish_validation with one row per check (failures first, then warnings and skipped checks), containing:

Test

Description of the check performed.

Status

"PASS", "FAIL", "WARN" (worth fixing, but not a failure), or "SKIP" (the check could not be run).

Details / Guidance

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.

Examples

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)


Validate the current project from the RStudio Addins menu

Description

Binding for the RStudio addin Addins > Validate psych-DS-ish project. It runs validator() on the open RStudio project (or, if no project is open, the working directory), prints the results to the console, and shows them as a colour-coded table in the Viewer pane.

Usage

validator_addin(project_root = NULL, viewer = TRUE)

Arguments

project_root

Character scalar or NULL. Path to the project root. If NULL (default), the open RStudio project is used, or the working directory if no project is open.

viewer

Logical. If TRUE (default), show the results table in the RStudio Viewer pane when running inside RStudio.

Value

(Invisibly) the psychdsish_validation results from validator().

Examples

project <- file.path(tempdir(), "my_project")
create_project_skeleton(project, quiet = TRUE)
validator_addin(project, viewer = FALSE)
unlink(project, recursive = TRUE)


Write a psych-DS dataset_description.json from the project's codebooks

Description

Creates or updates dataset_description.json in the project root, which the psych-DS standard requires. The variables it describes are taken from the codebooks created by the codebook chunk in code/processing.qmd, so that each variable is described once, in the codebook, rather than twice.

Usage

write_dataset_description(
  project_root,
  name = NULL,
  description = NULL,
  quiet = FALSE
)

Arguments

project_root

Character scalar. Path to the project root, e.g., "../" from code/processing.qmd.

name

Character scalar. The dataset's name. Defaults to the name in an existing dataset_description.json, or the project folder's name.

description

Character scalar. A description of the dataset. Defaults to the description in an existing file, or a placeholder to complete by hand.

quiet

Logical. If FALSE (default), a one-line summary is printed as a message.

Details

Documenting variables in a codebook .csv is the simpler option, and is all that validator() requires. Writing them to dataset_description.json as well is more work, but makes the project closer to a valid psych-DS dataset, which is machine-readable and easier for others to reuse. Use whichever suits the project; you do not need both.

Each codebook row becomes a PropertyValue entry in variableMeasured, mapping the codebook's variable, description, and units columns onto name, description, and unitText. A coding entry that is not "none" is appended to the description, because psych-DS has no separate field for it. Where the same variable appears in more than one codebook, the first description is used.

Fields that the file already contains and that this function does not write (e.g., author or license) are kept.

Data file names in the templates follow the psych-DS convention of key-value pairs ending in ⁠_data⁠, e.g., ⁠study-1_stage-processed_data.csv⁠. To check a project against the standard itself, use the psych-DS validator (https://psych-ds.github.io/validator/).

Value

(Invisibly) a list with path, name, description, and variables (the variable names written).

See Also

create_project_skeleton(), validator()

Examples

project <- file.path(tempdir(), "psychds_project")
create_project_skeleton(project, quiet = TRUE)

# normally written by the codebook chunk in code/processing.qmd
write.csv(
  data.frame(
    variable = c("id", "rt"),
    description = c("Participant identifier", "Response time"),
    units = c("none", "milliseconds"),
    coding = c("none", "none")
  ),
  file.path(project, "data", "processed", "stage-processed_codebook.csv"),
  row.names = FALSE
)

write_dataset_description(project, name = "My study", description = "A demo")
cat(readLines(file.path(project, "dataset_description.json")), sep = "\n")

unlink(project, recursive = TRUE)