Skip to contents

Creates a new study directory within the project's data/ folder, containing template metadata.yml and data.csv files based on the project's schema. These files can then be manually edited.

Usage

add_study_template(path = ".", study_id, overwrite = FALSE)

Arguments

path

Character string. The path to the root directory of the metawoRld project. Defaults to the current working directory (.).

study_id

Character string. A unique identifier for the study (e.g., PMID, DOI, or a custom ID). This will be used as the directory name. Should be filesystem-friendly.

overwrite

Logical. If a directory for study_id already exists, should its contents be overwritten with new templates? Defaults to FALSE.

Value

Invisibly returns the path to the created study directory containing the template files.

Examples

if (FALSE) { # \dontrun{
# --- Setup: Create a temporary project ---
proj_path <- file.path(tempdir(), "add_template_test")
create_metawoRld(
  path = proj_path,
  project_name = "Add Template Test",
  project_description = "Testing add_study_template()"
)

# --- Add a template for a new study ---
add_study_template(
  path = proj_path,
  study_id = "FutureStudy2024"
)

# Verify template files were created
list.files(file.path(proj_path, "data", "FutureStudy2024"))

# View the contents of the template metadata.yml
cat(readLines(file.path(proj_path, "data", "FutureStudy2024", "metadata.yml")), sep = "\n")

# View the contents of the template data.csv
cat(readLines(file.path(proj_path, "data", "FutureStudy2024", "data.csv")), sep = "\n")

# Try adding again without overwrite (should fail)
tryCatch(
  add_study_template(proj_path, "FutureStudy2024"),
  error = function(e) print(e$message)
)

# Add again with overwrite
add_study_template(
 path = proj_path,
 study_id = "FutureStudy2024",
 overwrite = TRUE
)

# --- Clean up ---
unlink(proj_path, recursive = TRUE)
} # }