View source: R/create_project_skeleton.R
| create_project_skeleton | R Documentation |
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.
create_project_skeleton(
project_root,
overwrite = FALSE,
rproj = TRUE,
quarto_yml = TRUE,
studies = 1,
layout = c("by_study", "by_type"),
quiet = FALSE
)
project_root |
Character scalar. Path to the root directory where
the project skeleton should be created, e.g., |
overwrite |
Logical. If |
rproj |
Logical. If |
quarto_yml |
Logical. If |
studies |
Whole number. The number of studies in the project.
Defaults to |
layout |
Character. How a multi-study project is arranged (ignored if
In both layouts, |
quiet |
Logical. If |
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
(Invisibly) a data.frame with one row per directory or file the function
handled, containing:
Path relative to project_root.
Either "dir" or "file".
"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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.