project_add_directory: Add custom directories to an existing project

View source: R/project_directories.R

project_add_directoryR Documentation

Add custom directories to an existing project

Description

Adds new directories to a project's configuration and creates them on the filesystem. This function is used by the GUI to allow users to add custom directories to their project structure without modifying existing directories.

Usage

project_add_directory(project_path, key, label, path)

Arguments

project_path

Character string. Absolute path to the project root directory.

key

Character string. Internal key for the directory (e.g., "analysis_archive"). Must be unique within the project's directory configuration.

label

Character string. Human-readable label for the directory (e.g., "Analysis Archive").

path

Character string. Relative path where the directory should be created (e.g., "analysis/archive"). Must be relative, not absolute. Parent directories will be created as needed.

Details

This function performs the following steps:

  1. Validates all input arguments

  2. Reads the project's config.yml file

  3. Checks for duplicate keys in existing directories

  4. Adds the new directory to the directories section

  5. Writes the updated config.yml back to disk

  6. Creates the directory on the filesystem (with recursive creation)

The function follows a non-destructive, additive-only approach. It will not:

  • Rename existing directories

  • Delete existing directories

  • Modify existing directory paths

  • Change the project type

Value

List with success status and directory information:

  • success: Logical indicating whether the operation succeeded

  • directory: List containing key, label, path, absolute_path, and created flag

  • error: Character string with error message (only present if success is FALSE)

Safety

The function includes several safety checks:

  • Rejects absolute paths (must be relative)

  • Rejects paths containing ".." (no directory traversal)

  • Checks for duplicate keys before adding

  • Wraps filesystem operations in error handling


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