Skip to contents

Keeps the poliovirus detections in a set of countries whose virus type matches a pattern, optionally from a set of surveillance sources, and keeps one row per detection.

Usage

detection_slice(
  detections,
  countries = c("AFG", "PAK"),
  vtype_pattern = "^WPV|^cVDPV|^VDPV|^aVDPV|^iVDPV",
  sources = NULL,
  key = c("epid", "vtype"),
  latest_by = NULL,
  cols = list()
)

Arguments

detections

A data frame of virus detections, one row per record, such as the output of clean_virus().

countries

ISO3 codes of the countries to keep. NULL keeps every country with a code. Default c("AFG", "PAK").

vtype_pattern

Regular expression a virus type must match to count. Default "^WPV|^cVDPV|^VDPV|^aVDPV|^iVDPV", which keeps wild poliovirus and every kind of vaccine-derived poliovirus.

sources

Surveillance sources to keep, matched against the source column. NULL (the default) keeps every source.

key

Columns that identify one detection. Default c("epid", "vtype"). Give the names as they appear in detections.

latest_by

Columns to sort on, in descending order, before duplicates are dropped. Default NULL, which keeps the first record in the input.

cols

Named list overriding the default column names, keyed by table, for example list(detections = list(vtype = "VirusTypeName")). This function reads the detections roles epid, vtype, country, source and virus_date, by default the clean_virus() names epid, vtype, country_iso3code, source and virus_date.

Value

A tibble with the columns of detections, one row per detection, ordered by virus date, country and EPID.

Details

The virus type is first written in one form: white space is removed and a leading WILD becomes WPV, so that the raw POLIS label WILD1 and the cleaned label WPV 1 both read WPV1. The pattern is matched against this form, and the returned table carries it in the virus type column.

A detection is identified by the columns in key. By default one EPID with two serotypes is two detections, and repeated records of one EPID and serotype are one. When latest_by is given, rows are sorted on those columns in descending order before duplicates are dropped, so the most recently edited record is kept. Otherwise the first record in the input is kept.

The function does not add laboratory-confirmed detections that POLIS does not yet hold. A caller that needs them adds them to detections first.

Examples

detections <- tibble::tibble(
  epid = c("A-1", "A-1", "A-2", "B-1"),
  vtype = c("WPV 1", "WPV 1", "cVDPV 2", "WPV 1"),
  country_iso3code = c("AFG", "AFG", "AFG", "NGA"),
  source = "AFP",
  virus_date = as.Date(c("2024-01-05", "2024-01-05", "2024-02-01",
                         "2024-03-01"))
)
detection_slice(detections)
#> # A tibble: 2 × 5
#>   epid  vtype  country_iso3code source virus_date
#>   <chr> <chr>  <chr>            <chr>  <date>    
#> 1 A-1   WPV1   AFG              AFP    2024-01-05
#> 2 A-2   cVDPV2 AFG              AFP    2024-02-01
detection_slice(detections, vtype_pattern = "^WPV1$")
#> # A tibble: 1 × 5
#>   epid  vtype country_iso3code source virus_date
#>   <chr> <chr> <chr>            <chr>  <date>    
#> 1 A-1   WPV1  AFG              AFP    2024-01-05