| Title: | Opinionated Project Scaffolding via Composable Themes |
|---|---|
| Description: | Provides a composable theme system for project scaffolding. Themes are ordered lists of steps that deploy files, inline text, or execute functions, with per-file merge strategies for handling pre-existing content. Includes pre-set themes for R analysis projects, targets workflows, and Claude Code agent configuration. |
| Authors: | Ben Zipperer [aut, cre], Economic Policy Institute [cph, fnd] |
| Maintainer: | Ben Zipperer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-05-29 09:21:58 UTC |
| Source: | https://github.com/economic/prefab |
Creates a theme that deploys Claude Code agent settings and rules for an R analysis project.
claude_r_analysis(settings_json = TRUE)claude_r_analysis(settings_json = TRUE)
settings_json |
Logical. If |
A prefab_theme object.
claude_r_analysis()claude_r_analysis()
Creates a theme that deploys Claude Code agent settings and rules for an R package.
claude_r_package()claude_r_package()
A prefab_theme object.
claude_r_package()claude_r_package()
Creates a theme that deploys Claude Code agent settings and rules for an R targets project.
claude_r_targets(settings_json = TRUE)claude_r_targets(settings_json = TRUE)
settings_json |
Logical. If |
A prefab_theme object.
claude_r_targets()claude_r_targets()
Creates a new project directory and applies a theme to it. If RStudio is available, opens the new project in a new session.
create_project(path, theme)create_project(path, theme)
path |
Path for the new project directory. Resolved to an absolute path
via |
theme |
A |
The normalized project path (invisibly).
## Not run: create_project("~/projects/my-analysis", r_analysis()) create_project("my-targets-project", r_targets() + claude_r_targets()) ## End(Not run)## Not run: create_project("~/projects/my-analysis", r_analysis()) create_project("my-targets-project", r_targets() + claude_r_targets()) ## End(Not run)
Returns a step-builder function that resolves source paths relative to a local directory. The directory path is resolved to an absolute path at creation time.
from_dir(path)from_dir(path)
path |
Path to the directory. Resolved to absolute via |
A function with signature
function(source, dest, strategy = "overwrite", data = NULL) that returns
a step_file() object.
Returns a step-builder function that resolves source paths relative to a
package's inst/ directory. Works with both installed packages and during
development with devtools::load_all().
from_package(package)from_package(package)
package |
Package name (string). |
A function with signature
function(source, dest, strategy = "overwrite", data = NULL) that returns
a step_file() object.
Sources an R file containing custom theme functions into the global
environment, making them available for use with use_theme() and
create_project().
load_themes(file = NULL)load_themes(file = NULL)
file |
Path to an R file defining theme functions. If |
The file is resolved in order: the explicit file argument, then the
PREFAB_THEMES environment variable, then ~/.prefab-themes.R.
The file path that was sourced (invisibly), or NULL invisibly if
no file was found.
## Not run: # Source from default locations load_themes() # Source from a specific file load_themes("~/my-org-themes.R") ## End(Not run)## Not run: # Source from default locations load_themes() # Source from a specific file load_themes("~/my-org-themes.R") ## End(Not run)
Constructs a theme from step objects. NULL arguments are silently dropped,
enabling conditional steps via if (cond) step(...).
new_theme(...)new_theme(...)
... |
Step objects ( |
A list with class "prefab_theme" containing a steps element.
Creates a theme that scaffolds a simple R analysis project with main.R,
README.md, and .gitignore.
r_analysis(data_dirs = TRUE)r_analysis(data_dirs = TRUE)
data_dirs |
Logical. If |
A prefab_theme object.
r_analysis()r_analysis()
Creates a theme that scaffolds an R targets project with _targets.R,
packages.R, README.md, and .gitignore.
r_targets()r_targets()
A prefab_theme object.
r_targets()r_targets()
Creates a step that deploys a file or directory to the project.
step_file(source, dest, strategy = "overwrite", data = NULL)step_file(source, dest, strategy = "overwrite", data = NULL)
source |
Absolute path to the source file or directory. Typically
produced by a source helper ( |
dest |
Path to the destination, relative to the project root. |
strategy |
How to handle a pre-existing destination file. One of
|
data |
|
A list with class "prefab_step_file".
Creates a step that executes an R function for its side effects.
step_run(fn, ..., .label = NULL)step_run(fn, ..., .label = NULL)
fn |
A function to execute. |
... |
Additional arguments passed to |
.label |
Optional label for display. When |
A list with class "prefab_step_run".
Creates a step that deploys inline text content to the project. Like
step_file() but takes a character vector instead of a source file path.
step_text(content, dest, strategy = "overwrite")step_text(content, dest, strategy = "overwrite")
content |
Character vector of lines to deploy (one element per line).
|
dest |
Path to the destination, relative to the project root. |
strategy |
How to handle a pre-existing destination file. One of
|
A list with class "prefab_step_text".
Prints the R code that would reproduce the given theme via cat(), and
returns the code invisibly as a single character string.
theme_code(theme)theme_code(theme)
theme |
A |
The generated R code as a single character string (invisibly).
Converts a directory tree into a theme where each file becomes a
step_file(). An optional _prefab.yml sidecar file in the directory
can override the strategy and template data per file.
theme_from_dir(path, strategy = "skip")theme_from_dir(path, strategy = "skip")
path |
Path to a directory of template files. Resolved to an absolute
path via |
strategy |
Default merge strategy for all files. Can be overridden
per file via a |
A prefab_theme object.
## Not run: # Create a theme from a directory of config files use_theme(theme_from_dir("~/my-template")) # Compose with other themes use_theme(r_analysis() + theme_from_dir("~/my-extras")) ## End(Not run)## Not run: # Create a theme from a directory of config files use_theme(theme_from_dir("~/my-template")) # Compose with other themes use_theme(r_analysis() + theme_from_dir("~/my-extras")) ## End(Not run)
Discovers the project root and executes the theme against it.
use_theme(theme)use_theme(theme)
theme |
A |
The project root path (invisibly).
## Not run: use_theme(r_analysis()) use_theme(r_analysis() + claude_r_analysis()) ## End(Not run)## Not run: use_theme(r_analysis()) use_theme(r_analysis() + claude_r_analysis()) ## End(Not run)