
Copy Elements from One Project to Another
Source:R/project-functions.R
boilerplate_copy_from_project.Rd
This function allows selective copying of boilerplate elements from one project to another, enabling controlled sharing of content between projects.
Usage
boilerplate_copy_from_project(
from_project,
to_project,
paths = NULL,
prefix = NULL,
data_path = NULL,
merge_strategy = c("skip", "overwrite", "rename"),
confirm = TRUE,
quiet = FALSE
)
Arguments
- from_project
Character. Name of the source project.
- to_project
Character. Name of the destination project.
- paths
Character vector. Paths to copy (e.g., c("measures.anxiety", "methods.sampling")). If NULL, copies everything (requires confirmation).
- prefix
Character. Optional prefix to add to copied entries to avoid conflicts. For example, prefix = "colleague_" would rename "anxiety" to "colleague_anxiety".
- data_path
Character. Base path for boilerplate data. If NULL, uses default location.
- merge_strategy
Character. How to handle conflicts: "skip", "overwrite", or "rename".
- confirm
Logical. If TRUE, asks for confirmation. Default is TRUE.
- quiet
Logical. If TRUE, suppresses messages. Default is FALSE.
Examples
# \donttest{
# Create temporary directory for example
temp_dir <- tempfile()
dir.create(temp_dir)
# Initialise two projects
boilerplate_init(data_path = temp_dir, project = "colleague_measures",
create_dirs = TRUE, confirm = FALSE, quiet = TRUE)
boilerplate_init(data_path = temp_dir, project = "my_research",
create_dirs = TRUE, confirm = FALSE, quiet = TRUE)
# Add some content to source project
source_db <- boilerplate_import(data_path = temp_dir,
project = "colleague_measures", quiet = TRUE)
source_db$measures$anxiety <- list(name = "Anxiety Scale", items = 10)
source_db$measures$depression <- list(name = "Depression Scale", items = 20)
boilerplate_save(source_db, data_path = temp_dir,
project = "colleague_measures", confirm = FALSE, quiet = TRUE)
# Copy specific measures from colleague's project
boilerplate_copy_from_project(
from_project = "colleague_measures",
to_project = "my_research",
paths = c("measures.anxiety", "measures.depression"),
prefix = "smith_",
data_path = temp_dir,
confirm = FALSE,
quiet = TRUE
)
# Clean up
unlink(temp_dir, recursive = TRUE)
# }