all_lkps_maps_to_db: Build a SQLite database of clinical code look up and mapping...

View source: R/lookups_and_mappings.R

all_lkps_maps_to_dbR Documentation

Build a SQLite database of clinical code look up and mapping tables

Description

Write the output from build_all_lkps_maps to a SQLite database.

Usage

all_lkps_maps_to_db(
  all_lkps_maps = build_all_lkps_maps(),
  db_path = "all_lkps_maps.db",
  overwrite = FALSE
)

Arguments

all_lkps_maps

A named list of look up and mapping tables, created by build_all_lkps_maps.

db_path

Where the database will be created. If an SQLite database file already exists here, then the lookup and mapping tables will be added to this. If NULL (default), then no database will be created/modified.

overwrite

If TRUE, overwrite tables in the database if they already exist. Default value is FALSE.

Value

Returns db_path invisibly

See Also

build_all_lkps_maps()

Examples

# build dummy all_lkps_maps resource (supressing warning messages)
all_lkps_maps_dummy <- build_all_lkps_maps_dummy()

# write to SQLite database file
db_path <- suppressMessages(
  all_lkps_maps_to_db(
    all_lkps_maps = all_lkps_maps_dummy,
    db_path = tempfile()
  )
)

# connect to SQLite database
con <- DBI::dbConnect(RSQLite::SQLite(), db_path)

# create named list of tbl_dbi objects
all_lkps_maps_dummy_db <- ukbwranglr::db_tables_to_list(con)

head(all_lkps_maps_dummy_db$icd10_lkp)

# import to R with dplyr::collect()
dplyr::collect(all_lkps_maps_dummy_db$icd10_lkp)

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