View source: R/project_directories.R
| project_add_directory | R Documentation |
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.
project_add_directory(project_path, key, label, path)
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. |
This function performs the following steps:
Validates all input arguments
Reads the project's config.yml file
Checks for duplicate keys in existing directories
Adds the new directory to the directories section
Writes the updated config.yml back to disk
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
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)
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.