linelist-package {linelist}R Documentation

Base Tools for Storing and Handling Case Line Lists

Description

The linelist package provides tools to help storing and handling case line list data. The linelist class adds a tagging system to classical data.frame or tibble objects which permits to identify key epidemiological data such as dates of symptom onset, epi case definition, age, gender or disease outcome. Once tagged, these variables can be seamlessly used in downstream analyses, making data pipelines more robust and reliable.

Main functions

Dedicated methods

Specific methods commonly used to handle data.frame are provided for linelist objects, typically to help flag or prevent actions which could alter or lose tagged variables (and may thus break downstream data pipelines).

Author(s)

Maintainer: Chris Hartgerink chris@data.org (ORCID) [reviewer]

Authors:

Other contributors:

See Also

Useful links:

Examples


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


[Package linelist version 2.0.1 Index]