validate_types {linelist}R 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

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")))
}

[Package linelist version 1.1.4 Index]