validate_types: Check tagged variables are the right class

View source: R/validate_types.R

validate_typesR Documentation

Check tagged variables are the right class

Description

This function checks the class of each tagged variable in a linelist against pre-defined accepted classes in tags_types().

Usage

validate_types(x, ref_types = tags_types())

Arguments

x

a linelist object

ref_types

a list providing allowed types for all tags, as returned by tags_types()

Value

A named list.

See Also

  • tags_types() to change allowed types

  • validate_tags() to perform a series of checks on the tags

  • validate_linelist() to combine validate_tags and validate_types

Examples

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

  ## create an invalid linelist - gender is a numeric
  x <- measles_hagelloch_1861 %>%
    tibble() %>%
    make_linelist(
      id = "case_ID",
      gender = "infector"
    )
  x

  ## the below would issue an error
  ## note: tryCatch is only used to avoid a genuine error in the example
  tryCatch(validate_types(x), error = paste)

  ## to allow other types, e.g. gender to be integer, character or factor
  validate_types(x, tags_types(gender = c("integer", "character", "factor")))
}

epiverse-trace/linelist documentation built on April 26, 2024, 5:35 a.m.