This function evaluates the validity of a linelist object by checking the
object class, its tags, and the types of the tagged variables. It combines
validations checks made by validate_types() and validate_tags(). See
'Details' section for more information on the checks performed.
Usage
validate_linelist(x, allow_extra = FALSE, ref_types = tags_types())Arguments
- x
a
linelistobject- allow_extra
a
logicalindicating if additional data tags not currently recognized bylinelistshould be allowed; ifFALSE, unknown tags will trigger an error- ref_types
a
listproviding allowed types for all tags, as returned bytags_types()
Details
The following checks are performed:
xis alinelistobjectxhas a well-formedtagsattributeall default tags are present (even if
NULL)all tagged variables correspond to existing columns
all tagged variables have an acceptable class
(optional)
xhas no extra tag beyond the default tags
See also
tags_types()to change allowed typesvalidate_types()to check if tagged variables have the right classesvalidate_tags()to perform a series of checks on the tags
Examples
if (require(outbreaks)) {
## create a valid linelist
x <- measles_hagelloch_1861 |>
make_linelist(
id = "case_ID",
date_onset = "date_of_prodrome",
age = "age",
gender = "gender"
)
x
## validation
validate_linelist(x)
## create an invalid linelist - onset date is a factor
x <- measles_hagelloch_1861 |>
make_linelist(
id = "case_ID",
date_onset = "gender",
age = "age"
)
x
## the below issues an error
## note: tryCatch is only used to avoid a genuine error in the example
tryCatch(validate_linelist(x), error = paste)
}
#> 'x' is a valid linelist object
#> [1] "Error: Some tags have the wrong class:\n - date_onset: Must inherit from class 'integer'/'numeric'/'Date'/'POSIXct'/'POSIXlt', but has class 'factor'\n\n"