Skip to contents

Returns a codelist with descriptions for the codes of interest. Supports flexible input: character vectors, || separated strings, or data frames.

Usage

CODES(
  ...,
  type = getOption("codeminer.code_type"),
  lookup_version = getOption("codeminer.lookup_version", default = "latest"),
  preferred_description_only = TRUE,
  col_filters = "default"
)

CODES_LIKE(
  pattern,
  type = getOption("codeminer.code_type"),
  lookup_version = getOption("codeminer.lookup_version", default = "latest"),
  preferred_description_only = TRUE,
  col_filters = "default"
)

Arguments

...

Codes to look up. Can be:

  • Character vectors: CODES("E10", "E11", type = "ICD-10")

  • || separated strings: CODES("E10 || E11", type = "ICD-10")

  • Data frame with code/description/code_type columns: CODES(my_df)

  • Mixed: CODES("E10", my_vector, "E13 || E14", type = "ICD-10")

Special values: "all" returns all codes; empty input returns empty codelist.

Comments can be added with << >> syntax: "E10 << Type 1 diabetes >>".

type

character. Type of clinical code system to be searched. Optional if input is a data frame with code_type column. Depends on what is available in the lookup tables. See add_lookup_table() on how to add new lookup tables. This can also be configured through the codeminer.code_type option.

lookup_version

character. Version of the lookup table to use. Default: "latest". Can be configured through the codeminer.lookup_version option.

preferred_description_only

logical. If TRUE, only returns the preferred description for each code. Default: FALSE.

col_filters

Column filters for the tables this query touches. One of:

  • "default" (default): apply session-pinned filters (codeminer_set_col_filters()) where set, else the metadata-defined default filters.

  • NULL (or NA): no filtering for any table this query touches.

  • A table-keyed list — the shape returned by get_col_filters() — with top-level names lookup / relationship / mapping, keyed by code type (or "from > to" pair for mappings), e.g. list(lookup = list("SNOMED CT" = list(active_concept = "1"))). Each table entry replaces that table's pinned/default filters wholesale; tables the list does not name keep their pins/defaults. NA as a table entry un-filters that one table. The filters reach every table the query touches (e.g. both the mapping table and the target lookup in MAP()).

To tweak one column while keeping a table's other default filters, amend get_col_filters() output and pass it back. Entries that match no registered table or column trigger a warning.

pattern

a regular expression to search for

Value

A codeminer_codelist object (tibble) containing the codes and their descriptions

Details

CODES_LIKE searches for codes that match a given regular expression. The matching is case-insensitive.

See also

Examples

# Set up a temporary dummy database
temp_db <- tempfile(fileext = ".duckdb")
create_dummy_database(temp_db)
#> ✔ Dummy database ready to use!

# Multiple arguments
CODES("E10", "E11", type = "ICD-10")
#> ℹ Using "UKB v4" as the latest lookup version for "ICD-10".
#> <codeminer_codelist>: 2 codes
#> Code type: "ICD-10"
#> 
#> # A tibble: 2 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus ICD-10   
#> 2 E11   Type 2 diabetes mellitus ICD-10   

# With comments
CODES("E10 << Type 1 diabetes >>", type = "ICD-10")
#> <codeminer_codelist>: 1 code
#> Code type: "ICD-10"
#> 
#> # A tibble: 1 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus ICD-10   

# || separated string
CODES("E10 || E11", type = "ICD-10")
#> <codeminer_codelist>: 2 codes
#> Code type: "ICD-10"
#> 
#> # A tibble: 2 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus ICD-10   
#> 2 E11   Type 2 diabetes mellitus ICD-10   

# Splice operator
my_codes <- c("E10", "E11")
CODES(!!!my_codes, type = "ICD-10")
#> <codeminer_codelist>: 2 codes
#> Code type: "ICD-10"
#> 
#> # A tibble: 2 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus ICD-10   
#> 2 E11   Type 2 diabetes mellitus ICD-10   

# Data frame input
df <- data.frame(
  code = c("E10", "E11"),
  description = c("Type 1", "Type 2"),
  code_type = c("ICD-10", "ICD-10")
)
CODES(df)
#> <codeminer_codelist>: 2 codes
#> Code type: "ICD-10"
#> 
#> # A tibble: 2 × 3
#>   code  description              code_type
#>   <chr> <chr>                    <chr>    
#> 1 E10   Type 1 diabetes mellitus ICD-10   
#> 2 E11   Type 2 diabetes mellitus ICD-10   
CODES_LIKE("^E1", type = "ICD-10")
#> <codeminer_codelist>: 55 codes
#> Code type: "ICD-10"
#> 
#> # A tibble: 55 × 3
#>    code  description                                                   code_type
#>    <chr> <chr>                                                         <chr>    
#>  1 E10   Type 1 diabetes mellitus                                      ICD-10   
#>  2 E100  Type 1 diabetes mellitus With coma                            ICD-10   
#>  3 E101  Type 1 diabetes mellitus With ketoacidosis                    ICD-10   
#>  4 E102  Type 1 diabetes mellitus With renal complications             ICD-10   
#>  5 E103  Type 1 diabetes mellitus With ophthalmic complications        ICD-10   
#>  6 E104  Type 1 diabetes mellitus With neurological complications      ICD-10   
#>  7 E105  Type 1 diabetes mellitus With peripheral circulatory complic… ICD-10   
#>  8 E106  Type 1 diabetes mellitus With other specified complications   ICD-10   
#>  9 E107  Type 1 diabetes mellitus With multiple complications          ICD-10   
#> 10 E108  Type 1 diabetes mellitus With unspecified complications       ICD-10   
#> # ℹ 45 more rows