create_project_skeleton: Create an opinionated project directory skeleton following...

View source: R/create_project_skeleton.R

create_project_skeletonR Documentation

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):

  • ⁠code/⁠ - analysis and processing scripts (.qmd/.Rmd)

  • ⁠reports/⁠ - manuscripts, slides, preprints, etc.

  • ⁠data/⁠

    • ⁠data/raw/⁠ - immutable raw data + dictionaries/codebooks

    • ⁠data/processed/⁠ - cleaned datasets and dictionaries

    • ⁠data/outputs/⁠ - outputs from processing/analysis scripts

      • ⁠plots/⁠ - figures (.png, .pdf, etc.)

      • ⁠fitted_models/⁠ - saved model objects (e.g., .rds)

      • ⁠results/⁠ - tables, summaries, descriptive statistics

  • ⁠methods/⁠ - measurement instruments, implementation files

  • ⁠preregistration/⁠ - preregistration documents

  • ⁠tools/⁠ - utility scripts and reproducibility helpers

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):

  • LICENSE - CC BY 4.0 license text

  • README.md - skeleton README describing project aims and structure

  • ⁠<project_name>.Rproj⁠ - RStudio project file that does not save or restore the workspace (if rproj = TRUE)

  • ⁠_quarto.yml⁠ - Quarto project file listing the .qmd files to render, in order, when the whole project is rendered (processing before analysis) (if quarto_yml = TRUE)

  • CITATION.cff - citation metadata template; GitHub uses it to show a "Cite this repository" button

  • .gitignore - ignores R history, session data, caches, temp files, OS-specific clutter, and large output directories

  • code/analysis.qmd - Quarto analysis template with metadata, setup chunk, and sessionInfo() chunk

  • code/processing.qmd - Quarto processing template (same structure)

  • tools/project_creator.qmd - re-runs create_project_skeleton() from within the project, with an optional (not evaluated by default) chunk calling delete_project_skeleton() for testing

  • tools/project_validator.qmd - runs validator() on the project

  • tools/style_all_files.qmd - reproducibility tool to apply tidyverse code style to all .qmd, .Rmd, and .R files

Quarto .qmd files are pre-filled with:

  • YAML front matter including title, author, date, HTML output settings

  • Global options to suppress scientific notation, warnings, and messages

  • Setup chunk for loading packages and configuring the session

  • Session information chunk

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)


psychdsish documentation built on Nov. 29, 2026, 5:07 p.m.