Returns a data frame including descriptions for the codes of interest

lookup_codes(
  codes,
  code_type,
  all_lkps_maps = NULL,
  preferred_description_only = TRUE,
  standardise_output = TRUE,
  unrecognised_codes = "error",
  col_filters = default_col_filters(),
  .return_unrecognised_codes = FALSE
)

Arguments

codes

character. Vector of codes to lookup

code_type

character. The type of clinical code system to be searched. Must be one obnf, dmd, icd9, icd10, read2, read2_drugs, read3, opcs4, data_coding_3, data_coding_4, data_coding_5, data_coding_6, sct, or phecode)`.

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.

preferred_description_only

bool. Return only preferred descriptions for clinical codes with synonyms. Default value is TRUE.

standardise_output

bool. If TRUE (default), outputs a data frame with columns named 'code', 'description' and 'code_type'. Otherwise returns a data frame with all columns for the relevant lookup sheet from (UK Biobank resource 592).

unrecognised_codes

Either 'error' (default) or 'warning'. If any input codes are unrecognised, then either an error or warning will be raised.

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.

.return_unrecognised_codes

If TRUE, return a vector of unrecognised codes only.

Value

data frame

See also

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

Examples

# build dummy all_lkps_maps
all_lkps_maps_dummy <- build_all_lkps_maps_dummy()

# look up ICD10 codes
lookup_codes(
  codes = c("E10", "E11"),
  code_type = "icd10",
  all_lkps_maps = all_lkps_maps_dummy
)
#> # A tibble: 2 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus icd10    
#> 2 E11   Type 2 diabetes mellitus icd10