Check that age labels can be parsed and, optionally, whether the labels are complete, unique, start at zero, and end with an open age group.
Details
By default, check_age()
only tests whether
a set of labels can be parsed as single-year,
five-year, or life table age groups.
(See age_group_type()
for more on the three
types of age group.) However, it can
also apply the following tests:
complete
. Whetherx
includes all intermediate age groups, with no gaps. For instance, the labelsc("10-14", "15-19", "5-9")
are complete, while the labelsc("15-19", "5-9")
are not (because they are missing"10-14"
.)unique
. Whetherx
has duplicated labels.zero
. Whether the youngest age group inx
starts at age 0, ie whether it includes"0"
or"0-4"
.open
. Whether the oldest age group inx
has an "open" age group, such as"100+"
or"65+"
, that has no upper limit.
See also
reformat_age()
to convert age labels to the format used by poputils.
Examples
try(
check_age(c("10-14", "0-4", "15+"),
complete = TRUE)
)
#> Error in check_age(c("10-14", "0-4", "15+"), complete = TRUE) :
#> Age group "5-9" is missing.
try(
check_age(c("10-14", "5-9", "0-4", "5-9", "15+"),
unique = TRUE)
)
#> Error in check_age(c("10-14", "5-9", "0-4", "5-9", "15+"), unique = TRUE) :
#> Age group "5-9" is duplicated.
try(
check_age(c("10-14", "5-9", "15+"),
zero = TRUE)
)
#> Error in check_age(c("10-14", "5-9", "15+"), zero = TRUE) :
#> Youngest age group does not start at 0.
#> ℹ Youngest age group is "5-9".
try(
check_age(c("10-14", "0-4", "5-9"),
open = TRUE)
)
#> Error in check_age(c("10-14", "0-4", "5-9"), open = TRUE) :
#> Oldest age group is not open.
#> ℹ Oldest age group is "10-14".