Add the location to a table
Arguments
- x
A
cdm_tablecontaining a person identifier column namedperson_idorsubject_id.- from
A character vector specifying the location sources to try, in priority order. The first source that provides a location is used. Supported values are
location_idandcare_site_id.- nameStyle
A character string specifying the name of the new column.
- name
A character string specifying the name of the output table. If
NULL, a temporary table is created.- locationSource
A character string specifying the column to retrieve from the
locationtable. Supported values includelocation_source_value,city,state,zip,county,country_concept_id, andcountry_source_value.- missingLocationValue
A character string used to replace missing location values.
Examples
# \donttest{
library(omock)
library(duckdb)
library(OmopIndices)
library(dplyr)
library(CohortConstructor)
cdm <- mockCdmFromDataset(datasetName = "GiBleed", source = "duckdb")
#> ℹ Loading bundled GiBleed tables from package data.
#> ℹ Adding drug_strength table.
#> ℹ Creating local <cdm_reference> object.
#> ℹ Inserting <cdm_reference> into duckdb.
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmplwnqmn/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
cdm$cohort <- conceptCohort(
cdm = cdm,
conceptSet = list(sinusitis = c(257012L, 4283893L, 4294548L, 40481087L)),
name = "cohort"
)
#> ℹ Subsetting table condition_occurrence using 4 concepts with domain:
#> condition.
#> ℹ Combining tables.
#> ℹ Creating cohort attributes.
#> ℹ Applying cohort requirements.
#> ℹ Merging overlapping records.
#> ✔ Cohort cohort created.
cdm$cohort |>
addLocation() |>
select(subject_id, cohort_start_date, location) |>
glimpse()
#> ℹ Trying to get location from: location_id.
#> ✖ Location could not be added from location_id.
#> ℹ Trying to get location from: care_site_id.
#> ✖ Location could not be added from care_site_id.
#> ! No location found, variable will be filled with `Missing`.
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 4246, 4268, 4270, 4333, 4392, 4398, 4401, 4474, 4475…
#> $ cohort_start_date <date> 1968-11-08, 1993-12-17, 2015-11-22, 1997-05-03, 201…
#> $ location <chr> "Missing", "Missing", "Missing", "Missing", "Missing…
# }
