Skip to contents

This function is partially deprecated. For basic list/get operations, please use boilerplate_import("measures") instead. Other functionality is maintained for backward compatibility.

This function manages measures in a boilerplate database, allowing for adding, updating, removing, retrieving, and listing measure entries.

Usage

boilerplate_manage_measures(
  action = c("add", "update", "remove", "get", "list", "save"),
  name = NULL,
  measure = NULL,
  db = NULL,
  measures_path = NULL,
  file_name = NULL,
  create_dirs = FALSE,
  confirm = TRUE,
  dry_run = FALSE,
  quiet = FALSE
)

boilerplate_manage_measures(
  action = c("add", "update", "remove", "get", "list", "save"),
  name = NULL,
  measure = NULL,
  db = NULL,
  measures_path = NULL,
  file_name = NULL,
  create_dirs = FALSE,
  confirm = TRUE,
  dry_run = FALSE,
  quiet = FALSE
)

Arguments

action

Character. Action to perform: "add", "update", "remove", "get", "list", or "save".

name

Character. Name of the measure to manage.

measure

List. Measure data (for add/update actions).

db

List. Optional database to use (required for "save", optional for other actions).

measures_path

Character. Path to the directory where measures database files are stored. If NULL (default), uses the "boilerplate/data/" subdirectory of the current working directory via the here::here() function.

file_name

Character. Name of the file to save or load (without path). If NULL (default), uses "measures_db.rds". Note: For "save" action, file_name must be explicitly provided.

create_dirs

Logical. If TRUE, creates directories that don't exist. Default is FALSE.

confirm

Logical. If TRUE, asks for confirmation before creating directories or modifying files. Default is TRUE.

dry_run

Logical. If TRUE, simulates the operation without writing files. Default is FALSE.

quiet

Logical. If TRUE, suppresses all CLI alerts. Default is FALSE.

Value

Depends on the action (see original function documentation).

Depending on the action:

  • "add", "update", "remove": The modified database (list).

  • "get": The measure data (list).

  • "list": The entire database (list).

  • "save": Invisible NULL (called for side effects).

Examples

# Create a temporary directory
temp_dir <- tempdir()
data_path <- file.path(temp_dir, "boilerplate_manage_example", "data")

# Initialise measures database
boilerplate_init(
  categories = "measures",
  data_path = data_path,
  create_dirs = TRUE,
  create_empty = TRUE,
  confirm = FALSE,
  quiet = TRUE
)

# List existing measures (initially empty)
measures_db <- boilerplate_manage_measures(
  action = "list",
  measures_path = data_path,
  quiet = TRUE
)

# Add a new measure
measures_db <- boilerplate_manage_measures(
  action = "add",
  name = "test_anxiety",
  measure = list(
    name = "Test Anxiety Scale",
    description = "A test anxiety measure for examples.",
    reference = "example2024",
    waves = "1-3",
    keywords = c("anxiety", "test"),
    items = list(
      "I feel anxious during tests",
      "Tests make me nervous"
    )
  ),
  measures_path = data_path,
  confirm = FALSE,
  quiet = TRUE
)

# Get the measure back
test_measure <- boilerplate_manage_measures(
  action = "get",
  name = "test_anxiety",
  measures_path = data_path,
  quiet = TRUE
)
test_measure$description
#> [1] "A test anxiety measure for examples."

# Clean up
unlink(file.path(temp_dir, "boilerplate_manage_example"), recursive = TRUE)