scaffold: Initialize and load the project environment

View source: R/scaffold.R

scaffoldR Documentation

Initialize and load the project environment

Description

The primary entry point for working with Framework projects. Call this at the start of every notebook or script to set up your environment with all configured packages, functions, and settings.

Usage

scaffold(config_file = NULL)

Arguments

config_file

Path to configuration file. If NULL (default), automatically discovers settings.yml or config.yml in the project.

Details

scaffold() performs the following steps in order:

  1. Standardizes working directory - Finds and sets the project root, even when called from notebooks in subdirectories

  2. Loads environment variables - Reads secrets from .env file

  3. Loads configuration - Parses settings.yml for project settings

  4. Sets random seed - For reproducibility (if seed is configured)

  5. Installs packages - Any missing packages from the packages list

  6. Loads packages - Attaches all configured packages

  7. Sources functions - Loads all .R files from ⁠functions/⁠ directory

After scaffold() completes, you have access to:

  • All packages listed in settings.yml

  • All functions from your ⁠functions/⁠ directory

  • Settings via settings("key") helper function

  • Database connections configured in your project

Value

Invisibly returns NULL. The main effects are side effects: loading packages, sourcing functions, and creating the config object.

Project Discovery

When called without arguments, scaffold() searches for a Framework project by:

  • Looking for settings.yml or config.yml in current and parent directories

  • Checking for .Rproj or .code-workspace files with nearby settings

  • Recognizing common Framework subdirectories (notebooks/, scripts/, etc.)

This means you can call scaffold() from any subdirectory within your project.

Configuration

The settings.yml file controls what scaffold() loads. Key settings include:

  • packages: List of R packages to install and load

  • seed: Random seed for reproducibility

  • directories: Custom directory paths

  • connections: Database connection configurations

See Also

  • project_create() to create a new Framework project

  • standardize_wd() for just the working directory standardization

  • settings() to access configuration values after scaffolding

Examples


if (FALSE) {
# At the top of every notebook or script:
library(framework)
scaffold()

# Now you can use your configured packages and functions
# Access settings via the settings() helper:
settings("directories.notebooks")
settings("seed")
}



framework documentation built on Feb. 18, 2026, 1:07 a.m.