Skip to contents

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")))
}
#> 
#> // linelist object
#> # A tibble: 188 × 12
#>    case_ID infector date_of_prodrome date_of_rash date_of_death   age gender
#>      <int>    <int> <date>           <date>       <date>        <dbl> <fct> 
#>  1       1       45 1861-11-21       1861-11-25   NA                7 f     
#>  2       2       45 1861-11-23       1861-11-27   NA                6 f     
#>  3       3      172 1861-11-28       1861-12-02   NA                4 f     
#>  4       4      180 1861-11-27       1861-11-28   NA               13 m     
#>  5       5       45 1861-11-22       1861-11-27   NA                8 f     
#>  6       6      180 1861-11-26       1861-11-29   NA               12 m     
#>  7       7       42 1861-11-24       1861-11-28   NA                6 m     
#>  8       8       45 1861-11-21       1861-11-26   NA               10 m     
#>  9       9      182 1861-11-26       1861-11-30   NA               13 m     
#> 10      10       45 1861-11-21       1861-11-25   NA                7 f     
#> # ℹ 178 more rows
#> # ℹ 5 more variables: family_ID <int>, class <fct>, complications <fct>,
#> #   x_loc <dbl>, y_loc <dbl>
#> 
#> // tags: id:case_ID, gender:infector