Skip to contents

**DANGER: This permanently deletes data from the database!**

This function safely deletes one or more individuals and all related data in the correct order to respect foreign key constraints: 1. Individual measurement features 2. Trait measurements 3. Individuals

**Plot metadata is preserved** (plot, subplots, and subplot features remain intact).

**Safety features:** - Dry-run mode to preview what will be deleted - Shows counts of all related data - Requires explicit confirmation (unless force = TRUE) - Uses database transaction (rolls back on error) - Detailed logging of each step

Usage

safe_delete_individuals(
  plot_name = NULL,
  individual_ids = NULL,
  tags = NULL,
  con = NULL,
  dry_run = TRUE,
  force = FALSE,
  verbose = TRUE
)

Arguments

plot_name

Character vector. Plot name(s) to delete individuals from

individual_ids

Integer vector. Specific individual ID(s) to delete (id_n from data_individuals). If NULL, deletes ALL individuals in the specified plot(s). Default NULL.

tags

Numeric vector. Specific tag numbers to delete. Alternative to individual_ids. If provided along with plot_name, deletes individuals matching those tags in those plots. Default NULL.

con

Database connection. If NULL, will connect automatically.

dry_run

Logical. If TRUE, shows what would be deleted without deleting. Default TRUE for safety.

force

Logical. If TRUE, skips confirmation prompts. Default FALSE. **USE WITH EXTREME CAUTION!**

verbose

Logical. Show detailed progress? Default TRUE.

Value

List with deletion summary (invisible)

Examples

if (FALSE) { # \dontrun{
con <- call.mydb()

# STEP 1: Always do dry-run first!
# Delete all individuals in a plot
safe_delete_individuals(plot_name = "mbalmayo010", dry_run = TRUE)

# Delete specific individuals by ID
safe_delete_individuals(individual_ids = c(12345, 12346), dry_run = TRUE)

# Delete specific individuals by tag and plot
safe_delete_individuals(plot_name = "mbalmayo010", tags = c(1, 2, 3), dry_run = TRUE)

# STEP 2: Review the output, then delete if sure
safe_delete_individuals(plot_name = "mbalmayo010", dry_run = FALSE)

# Delete multiple plots' individuals
safe_delete_individuals(plot_name = c("mbalmayo010", "mbalmayo011"))
} # }