
Compute stem vital status for specified individuals
compute_stem_vital_status.RdDerives a per-census vital status ("alive", "dead",
"presumed_dead", or NA) for each specified stem, applying the
same evidence hierarchy and retroactive correction used in the bulk
workflow_stem_status.R. Intended for incremental updates after new
measurements or observations are added, and as a backend for the feature
wizard Shiny app.
Usage
compute_stem_vital_status(
individual_ids,
add_data = FALSE,
dry_run = TRUE,
dead_patterns = c("\\bdead\\b", "\\bmort\\b"),
missing_patterns = c("\\bmissing\\b", "\\bnon\\s*vu\\b", "\\bdisparu\\b",
"\\bmanquant\\b", "suppos[eé]\\s*mort"),
alive_patterns = c("\\balive\\b", "\\bvivant\\b"),
con = NULL
)Arguments
- individual_ids
Integer vector of individual IDs (
id_n/id_data_individuals).- add_data
Logical. If
TRUE, upsert the computed statuses into the database: existingstem_statusrecords for these individuals are deleted, then the new statuses are inserted. DefaultFALSE.- dry_run
Logical. When
add_data = TRUE, preview the upsert without committing any changes. DefaultTRUE.- dead_patterns
Character vector of case-insensitive regexes identifying "dead" observation text.
- missing_patterns
Character vector of case-insensitive regexes identifying "missing" observation text.
- alive_patterns
Character vector of case-insensitive regexes identifying "alive" observation text.
- con
Database connection. Defaults to
call.mydb().
Value
A tibble with one row per individual \(\times\) census:
id_nIndividual ID
id_table_liste_plotsPlot ID
id_sub_plotsCensus subplot ID (used for DB linking)
plot_namePlot name
census_nameCensus label, e.g.
"census_1"census_dateDate of census
stem_vital_status"alive","dead","presumed_dead", orNA(before first measurement)missingLogical — stem was reported missing at this census
evidence_sourceHuman-readable summary of evidence used
Returned invisibly when add_data = TRUE and dry_run = FALSE.
Evidence sources (in priority order)
observations trait: regex patterns on free-text notes (
dead_patterns,missing_patterns,alive_patterns)flag2_rainfor: non-
"k"= dead;"k"= presumed_dead / missingstem_diameter: \(\ge 2\) consecutive missing censuses = dead; 1 consecutive missing census = presumed_dead
flag1_rainfor: presence is an alive indicator (informational; does not override stronger dead evidence)
Retroactive correction
If a stem is classified as "presumed_dead" at census N but
has a recorded diameter at a later census N+k, that earlier status
is corrected to "alive" (the stem was just temporarily unmeasured).
Examples
if (FALSE) { # \dontrun{
con <- call.mydb()
# Compute status for a few stems (read-only, no DB write)
result <- compute_stem_vital_status(individual_ids = c(101, 102, 103), con = con)
print(result)
# Compute and preview what would be written to the DB
compute_stem_vital_status(
individual_ids = c(101, 102, 103),
add_data = TRUE,
dry_run = TRUE,
con = con
)
# Compute and commit to the DB
compute_stem_vital_status(
individual_ids = c(101, 102, 103),
add_data = TRUE,
dry_run = FALSE,
con = con
)
} # }