get_mapping_df: Get a 'from-to' mapping data frame

View source: R/clinical_codes.R

get_mapping_dfR Documentation

Get a 'from-to' mapping data frame

Description

Returns a data frame with 'from' and 'to' columns for a specified pair of coding systems.

Usage

get_mapping_df(
  from,
  to,
  all_lkps_maps = NULL,
  rename_from_to = NULL,
  na.rm = TRUE,
  reverse_mapping = "error",
  col_filters = default_col_filters()
)

Arguments

from

A clinical coding system to map from.

to

A clinical coding system to map to.

all_lkps_maps

Either a named list of lookup and mapping tables (either data frames or tbl_dbi objects), or the path to a SQLite database containing these tables (see also build_all_lkps_maps() and all_lkps_maps_to_db()). If NULL, will attempt to connect to an SQLite database named 'all_lkps_maps.db' in the current working directory, or to a a SQLite database specified by an environmental variable named 'ALL_LKPS_MAPS_DB' (see here for how to set environment variables using a .Renviron file). The latter method will be used in preference.

rename_from_to

Optionally supply a named vector to rename the 'from' and 'to' columns. For example c(from = "original_codes", to = "new_codes"). By default, the columns will be named using the values for from and to arguments.

na.rm

If TRUE (default), remove any rows with NA from the returned mapping data frame. The mapping tables may sometimes include NA values to explicitly show which 'from' codes have not been mapped.

reverse_mapping

If 'error' (default), an error raised if attempting to map between coding systems for which a mapping table does not exist. If 'warning', will raise a warning and attempt to use an existing mapping table in the opposite direction (for example, a mapping from ICD10 to Read 3 would be attempted using the Read 3-to-ICD10 mapping table).

col_filters

A named list where each name in the list refers to the name of a lookup or mapping table. Each item is also a named list, where the names refer to column names in the corresponding table, and the items are vectors of values to filter for. For example, ⁠list(my_lookup_table = list(colA = c("A", "B"))⁠ will result in my_lookup_table being filtered for rows where colA is either 'A' or 'B'. Uses default_col_filters() by default. Set to NULL to remove all filters.

Value

A data frame with column names 'from' and 'to'.

See Also

Other Clinical code lookups and mappings: codes_starting_with(), default_col_filters(), lookup_codes(), map_codes(), reformat_icd10_codes()

Examples

# build dummy all_lkps_maps
all_lkps_maps_dummy <- build_all_lkps_maps_dummy()

# get mapping data frame for Read 2 to ICD10
get_mapping_df(
  from = "read3",
  to = "icd10",
  all_lkps_maps = all_lkps_maps_dummy
)

rmgpanw/codemapper documentation built on Aug. 30, 2023, 4:07 p.m.