This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
golem is an R package providing an opinionated framework for building production-grade Shiny applications as R packages. It scaffolds projects, manages modules, handles configuration, and supports deployment (Docker, RStudio Connect, etc.).
# Run tests
devtools::test()
# Run a single test file
testthat::test_file("tests/testthat/test-utils.R")
# Full R CMD check (must pass with 0 errors, 0 warnings, 0 notes)
devtools::check()
# Document (regenerate NAMESPACE, Rd files)
devtools::document()
# Load package for interactive testing
devtools::load_all()
# Lint
air format .- Formatter:
air format . - Pre-commit: uses
airformatter (see.pre-commit-config.yaml)
The scaffolding template copied by create_golem(). Contains the standard app structure: R/app_ui.R, R/app_server.R, R/app_config.R, R/run_app.R, inst/golem-config.yml, and dev scripts (dev/01_start.R, dev/02_dev.R, dev/03_deploy.R).
Files are grouped by functionality:
- Scaffolding:
create_golem.R— project creation - File generators:
add_files.R(JS/CSS/HTML),add_r_files.R(fct/utils/R6),add_dockerfiles.R,add_dockerfiles_renv.R - Module system:
modules_fn.R—add_module()createsmod_<name>.Rwith UI+server, optional_fct,_utils,_class, and test files - Configuration:
config.R,golem-yaml-get.R,golem-yaml-set.R,golem-yaml-utils.R,set_golem_options.R - Runtime:
with_opt.R(with_golem_options()),make_dev.R(dev/prod mode),bundle_resources.R,js.R - Templates:
templates.R— template functions for JS, CSS, SASS, HTML files - Bootstrap files:
bootstrap_*.R— lazy-load optional dependencies (cli, fs, usethis, roxygen2, etc.) - Messaging:
cats.R,cli_msg.R— console output helpers - Utilities:
utils.R,pkg_tools.R,desc.R
Controlled by getOption("golem.app.prod"). app_dev() / app_prod() check this. make_dev(fun) wraps any function to only execute in dev mode. Pre-made wrappers: cat_dev(), print_dev(), message_dev(), warning_dev().
YAML-based via inst/golem-config.yml using the config package. Supports default, production, dev profiles. Accessed via get_golem_config(). Environment variables: GOLEM_CONFIG_ACTIVE, R_CONFIG_ACTIVE.
Functions from suggested packages (cli, fs, usethis, etc.) are wrapped in bootstrap_*.R files that check availability and provide fallbacks, avoiding hard imports.
- Framework: testthat edition 3
- Key test helpers (in
tests/testthat/setup.R):perform_inside_a_new_golem(fun)— runsfuninside a fresh golem project in an isolatedcallrsessionrun_quietly_in_a_dummy_golem(expr)— creates a temporary golem project, runsexprinside it withwithr::with_dir, cleans up aftercreate_dummy_golem()— creates a throwaway golem in tempdirexpect_exists(path)— asserts file exists
- Tests use
callrfor process isolation andwithrfor temporary state - Snapshot tests live in
tests/testthat/_snaps/
- PRs target the
masterbranch, and should allow modification by maintainer - PR messages must reference the issue and include NEWS.md category:
## New Functions,## New features,## Breaking changes,## Bug fix,## Internal changes