if (require(outbreaks)) {
# using base R style
## dataset we'll create a linelist from, only using the first 50 entries
measles_hagelloch_1861[1:50, ]
## create linelist
x <- make_linelist(measles_hagelloch_1861[1:50, ],
id = "case_ID",
date_onset = "date_of_prodrome",
age = "age",
gender = "gender"
)
x
## check tagged variables
tags(x)
## robust renaming
names(x)[1] <- "identifier"
x
## example of dropping tags by mistake - default: warning
x[, 2:5]
## to silence warnings when taggs are dropped
lost_tags_action("none")
x[, 2:5]
## to trigger errors when taggs are dropped
# lost_tags_action("error")
# x[, 2:5]
## reset default behaviour
lost_tags_action()
# using tidyverse style
## example of creating a linelist, adding a new variable, and adding a tag
## for it
if (require(dplyr)) {
x <- measles_hagelloch_1861 |>
tibble() |>
make_linelist(
id = "case_ID",
date_onset = "date_of_prodrome",
age = "age",
gender = "gender"
) %>%
mutate(result = if_else(is.na(date_of_death), "survived", "died")) |>
set_tags(outcome = "result") |>
rename(identifier = case_ID)
head(x)
## extract tagged variables
x |>
select(has_tag(c("gender", "age")))
x |>
tags()
x |>
select(starts_with("date"))
}
}
Run the code above in your browser using DataLab