Skip to contents

This function evaluates the validity of the tags of a linelist object by checking that: i) tags are present ii) tags is a list of character iii) that all default tags are present iv) tagged variables exist v) that no extra tag exists (if allow_extra is FALSE).

Usage

validate_tags(x, allow_extra = FALSE)

Arguments

x

a linelist object

allow_extra

a logical indicating if additional data tags not currently recognized by linelist should be allowed; if FALSE, unknown tags will trigger an error

Value

If checks pass, a linelist object; otherwise issues an error.

See also

validate_types() to check if tagged variables have the right classes

Author

Thibaut Jombart thibaut@data.org

Examples

if (require(outbreaks) && require(dplyr) && require(magrittr)) {

  ## create a valid linelist
  x <- measles_hagelloch_1861 %>%
    tibble() %>%
    make_linelist(
      id = "case_ID",
      date_onset = "date_of_prodrome",
      age = "age",
      gender = "gender"
    )
  x

  ## validation
  validate_tags(x)

  ## hack to create an invalid tags (missing defaults)
  attr(x, "tags") <- list(id = "case_ID")

  ## the below issues an error
  ## note: tryCatch is only used to avoid a genuine error in the example
  tryCatch(validate_tags(x), error = paste)
}
#> [1] "Error in validate_tags(x): The following default tags are missing:\ndate_onset, date_reporting, date_admission, date_discharge, date_outcome, date_death, gender, age, location, occupation, hcw, outcome\n"