This function checks whether external data includes the required columns for a specific indicator type (`varname`) and appends it to an existing dataset repository (`repo`) if validation passes.

adding_data_extern(varname, repo, extern_data)

Arguments

varname

A character string indicating the type of indicator to validate. Supported values include: `"parous_rate"`, `"endophagy"`, `"endophily"`, `"sac_rate"`, `"indoor_HBI"`, `"outdoor_HBI"`, and `"HBI"`.

repo

A data frame representing the current dataset repository to which external data will be appended.

extern_data

A data frame containing the external data to validate and append. This data must contain all required columns for the specified `varname`.

Value

A data frame combining the original `repo` and the validated `extern_data`. If required columns are missing, the function stops with an informative error.

Details

Each `varname` has its own set of required columns in addition to core fields like `species`, `insecticide_control`, `country`, and `year_start`. For `"HBI"`, the function also checks for the columns required by both `"HBI_indoor"` and `"HBI_outdoor"`.

Examples

repo <- data.frame(
  species = character(),
  insecticide_control = character(),
  country = character(),
  year_start = integer(),
  parity_n = integer(),
  parity_total = integer(),
  parity_percent = numeric(),
  stringsAsFactors = FALSE
)

extern_data <- data.frame(
  species = c("Anopheles arabiensis", "Anopheles arabiensis"),
  insecticide_control = c("f", "f"),
  country = c("Kenya", "Ethiopia"),
  year_start = c(2021, 2022),
  parity_n = c(45, 30),
  parity_total = c(100, 60),
  parity_percent = c(45, 50),
  stringsAsFactors = FALSE
)

repo <- adding_data_extern("parous_rate", repo, extern_data)