| Title: | Methods and Classes for the OMOP Common Data Model |
|---|---|
| Description: | Provides definitions of core classes and methods used by analytic pipelines that query the OMOP (Observational Medical Outcomes Partnership) common data model. |
| Authors: | Martí Català [aut, cre] (ORCID: <https://orcid.org/0000-0003-3308-9905>), Edward Burn [aut] (ORCID: <https://orcid.org/0000-0002-9286-1128>), Mike Du [ctb] (ORCID: <https://orcid.org/0000-0002-9517-8834>), Yuchen Guo [ctb] (ORCID: <https://orcid.org/0000-0002-0847-4855>), Adam Black [ctb] (ORCID: <https://orcid.org/0000-0001-5576-8701>), Marta Alcalde-Herraiz [ctb] (ORCID: <https://orcid.org/0009-0002-4405-1814>) |
| Maintainer: | Martí Català <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 1.4.0 |
| Built: | 2026-06-18 10:18:59 UTC |
| Source: | https://github.com/darwin-eu/omopgenerics |
Subset a cdm reference object.
## S3 method for class 'cdm_reference' x[[name]]## S3 method for class 'cdm_reference' x[[name]]
x |
A cdm reference |
name |
The name or index of the table to extract from the cdm object. |
A single cdm table reference
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm[["person"]]library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm[["person"]]
Assign a table to a cdm reference.
## S3 replacement method for class 'cdm_reference' cdm[[name]] <- value## S3 replacement method for class 'cdm_reference' cdm[[name]] <- value
cdm |
A |
name |
Name where the new table will be assigned. |
value |
Table with the same source as the |
The cdm reference.
Subset a cdm reference object.
## S3 method for class 'cdm_reference' x$name## S3 method for class 'cdm_reference' x$name
x |
A cdm reference. |
name |
The name of the table to extract from the cdm object. |
A single cdm table reference
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm$personlibrary(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm$person
Assign a table to a cdm reference.
## S3 replacement method for class 'cdm_reference' cdm$name <- value## S3 replacement method for class 'cdm_reference' cdm$name <- value
cdm |
A |
name |
Name where the new table will be assigned. |
value |
Table with the same source as the |
The cdm reference.
library(omopgenerics) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm$personlibrary(omopgenerics) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdm$person
Required columns for each of the achilles result tables
achillesColumns(table, version = "5.3", onlyRequired = lifecycle::deprecated())achillesColumns(table, version = "5.3", onlyRequired = lifecycle::deprecated())
table |
Table for which to see the required columns. One of "achilles_analysis", "achilles_results", or "achilles_results_dist". |
version |
Version of the OMOP Common Data Model. |
onlyRequired |
deprecated. |
Character vector with the column names
library(omopgenerics) achillesColumns("achilles_analysis") achillesColumns("achilles_results") achillesColumns("achilles_results_dist")library(omopgenerics) achillesColumns("achilles_analysis") achillesColumns("achilles_results") achillesColumns("achilles_results_dist")
Names of the tables that contain the results of achilles analyses
achillesTables(version = "5.3")achillesTables(version = "5.3")
version |
Version of the OMOP Common Data Model. |
Names of the tables that contain the results from the achilles analyses
library(omopgenerics) achillesTables()library(omopgenerics) achillesTables()
Identifies and returns the unique values in additional_name column.
additionalColumns(result)additionalColumns(result)
result |
A |
Unique values of the additional name column.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> additionalColumns() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> additionalColumns() }
<summarised_result> objectAdd settings columns to a <summarised_result> object
addSettings(result, settingsColumn = settingsColumns(result))addSettings(result, settingsColumn = settingsColumns(result))
result |
A |
settingsColumn |
Settings to be added as columns, by default
|
A <summarised_result> object with the added setting columns.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> addSettings() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> addSettings() }
Assert that an object is a character and satisfies certain conditions.
assertCharacter( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, minNumCharacter = 0, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertCharacter( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, minNumCharacter = 0, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
minNumCharacter |
Minimum number of characters that all elements must have. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an object is one of a set of options.
assertChoice( x, choices, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertChoice( x, choices, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
choices |
Options that x is allowed to be. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an object has a certain class.
assertClass( x, class, length = NULL, null = FALSE, empty = TRUE, all = FALSE, extra = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertClass( x, class, length = NULL, null = FALSE, empty = TRUE, all = FALSE, extra = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
class |
Expected class or classes. |
length |
Required length. If |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
all |
Whether it should have all the classes or only at least one of them. |
extra |
Whether the object can have extra classes. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert Date
assertDate( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertDate( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Expression to check. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
x
Assert that an object is a list.
assertList( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, class = NULL, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertList( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, class = NULL, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
class |
Class that the elements must have. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an object is a logical.
assertLogical( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertLogical( x, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an object is a numeric.
assertNumeric( x, integerish = FALSE, min = -Inf, max = Inf, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertNumeric( x, integerish = FALSE, min = -Inf, max = Inf, length = NULL, na = FALSE, null = FALSE, empty = TRUE, unique = FALSE, named = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
integerish |
Whether it has to be an integer |
min |
Minimum value that the object can be. |
max |
Maximum value that the object can be. |
length |
Required length. If |
na |
Whether it can contain NA values. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique elements. |
named |
Whether it has to be named. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an object is a table.
assertTable( x, class = NULL, numberColumns = NULL, numberRows = NULL, columns = character(), allowExtraColumns = TRUE, null = FALSE, empty = TRUE, unique = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertTable( x, class = NULL, numberColumns = NULL, numberRows = NULL, columns = character(), allowExtraColumns = TRUE, null = FALSE, empty = TRUE, unique = FALSE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Variable to check. |
class |
A class that the table must have: "tbl", "data.frame", "tbl_sql", ... |
numberColumns |
Number of columns that it has to contain. |
numberRows |
Number of rows that it has to contain. |
columns |
Name of the columns required. |
allowExtraColumns |
Whether extra columns are allowed. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
unique |
Whether it has to contain unique rows. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Assert that an expression is TRUE.
assertTrue( x, null = FALSE, empty = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )assertTrue( x, null = FALSE, empty = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame(), msg = NULL )
x |
Expression to check. |
null |
Whether it can be NULL. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument that will be passed to |
msg |
Custom error message. |
Get attrition from an object.
attrition(x)attrition(x)
x |
An object for which to get an attrition summary. |
A table with the attrition.
Get cohort attrition from a cohort_table object.
## S3 method for class 'cohort_table' attrition(x)## S3 method for class 'cohort_table' attrition(x)
x |
A cohort_table |
A table with the attrition.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), cohort_end_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) attrition(cdm$cohort1)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), cohort_end_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) attrition(cdm$cohort1)
Bind two or more objects of the same class.
bind(...)bind(...)
... |
Objects to bind. |
New object.
Bind two or more cohort tables
## S3 method for class 'cohort_table' bind(..., name)## S3 method for class 'cohort_table' bind(..., name)
... |
Generated cohort set objects to bind. At least two must be provided. |
name |
Name of the new generated cohort set. |
The cdm object with a new generated cohort set containing all of the cohorts passed.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cohort1 <- tibble( cohort_definition_id = 1, subject_id = 1:3, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") ) cohort2 <- tibble( cohort_definition_id = c(2, 2, 3, 3, 3), subject_id = c(1, 2, 3, 1, 2), cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") ) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock", cohortTables = list("cohort1" = cohort1, "cohort2" = cohort2) ) cdm <- bind(cdm$cohort1, cdm$cohort2, name = "cohort3") settings(cdm$cohort3) cdm$cohort3library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cohort1 <- tibble( cohort_definition_id = 1, subject_id = 1:3, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") ) cohort2 <- tibble( cohort_definition_id = c(2, 2, 3, 3, 3), subject_id = c(1, 2, 3, 1, 2), cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") ) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock", cohortTables = list("cohort1" = cohort1, "cohort2" = cohort2) ) cdm <- bind(cdm$cohort1, cdm$cohort2, name = "cohort3") settings(cdm$cohort3) cdm$cohort3
Bind two or summarised_result objects
## S3 method for class 'summarised_result' bind(...)## S3 method for class 'summarised_result' bind(...)
... |
summarised_result objects |
A summarised_result object the merged objects.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock", cohortTables = list("cohort1" = tibble( cohort_definition_id = 1, subject_id = 1:3, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") )) ) result1 <- summary(cdm) result2 <- summary(cdm$cohort1) mergedResult <- bind(result1, result2) mergedResultlibrary(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock", cohortTables = list("cohort1" = tibble( cohort_definition_id = 1, subject_id = 1:3, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") )) ) result1 <- summary(cdm) result2 <- summary(cdm$cohort1) mergedResult <- bind(result1, result2) mergedResult
Separate the cdm tables in classes
cdmClasses(cdm)cdmClasses(cdm)
cdm |
A |
A list of table names, the name of the list indicates the class.
Disconnect from a cdm object.
cdmDisconnect(cdm, ...)cdmDisconnect(cdm, ...)
cdm |
A |
... |
For compatibility; not used. |
TRUE if the process was successful. library(omopgenerics) library(dplyr, warn.conflicts = FALSE)
person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "mock" )
cdmDisconnect(cdm)
Create a cdm object from local tables
cdmFromTables(tables, cdmName, cohortTables = list(), cdmVersion = NULL)cdmFromTables(tables, cdmName, cohortTables = list(), cdmVersion = NULL)
tables |
List of tables that are part of the cdm object. |
cdmName |
Name of the |
cohortTables |
List of tables that contain cohort, cohort_set and cohort_attrition attributes. |
cdmVersion |
Version of the OMOP Common Data Model. Supported versions are "5.3" and "5.4". |
A cdm_reference object.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" )library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" )
Get or set the name of a cdm_reference associated object
cdmName(x) cdmName(x) <- valuecdmName(x) cdmName(x) <- value
x |
A cdm_reference or cdm_table object. |
value |
Name to assign to the cdm_reference object. |
Name of the cdm_reference.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmName(cdm) cdmName(cdm$person) cdmName(cdm) <- "mock_2"library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmName(cdm) cdmName(cdm$person) cdmName(cdm) <- "mock_2"
cdm_reference of a cdm_table.Get the cdm_reference of a cdm_table.
cdmReference(table)cdmReference(table)
table |
A |
A cdm_reference.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmReference(cdm$person)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmReference(cdm$person)
Restrict the cdm object to a subset of tables.
cdmSelect(cdm, ...)cdmSelect(cdm, ...)
cdm |
A |
... |
Selection of tables to use, it supports tidyselect expressions. |
A cdm_reference with only the specified tables.
cdm <- emptyCdmReference("my cdm") cdm cdm |> cdmSelect("person")cdm <- emptyCdmReference("my cdm") cdm cdm |> cdmSelect("person")
Get the cdmSource of an object.
cdmSource(x, cdm = lifecycle::deprecated())cdmSource(x, cdm = lifecycle::deprecated())
x |
Object to obtain the cdmSource. |
cdm |
Deprecated, use x please. |
A cdm_source object.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmSource(cdm) cdmSource(cdm$person)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmSource(cdm) cdmSource(cdm$person)
cdmSourceType(cdm)cdmSourceType(cdm)
cdm |
A |
A character vector with the type of source of the cdm_reference object.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmSourceType(cdm)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmSourceType(cdm)
This is an internal developer focused function that creates a cdm_table from a table that shares the source but it is not a cdm_table. Please use insertTable if you want to insert a table to a cdm_reference object.
cdmTableFromSource(src, value)cdmTableFromSource(src, value)
src |
A cdm_source object. |
value |
A table that shares source with the cdm_reference object. |
A cdm_table.
Get the version of an object.
cdmVersion(x)cdmVersion(x)
x |
Object to know the cdm version of an object. |
A character vector indicating the cdm version.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmVersion(cdm) cdmVersion(cdm$person)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) cdmVersion(cdm) cdmVersion(cdm$person)
checkCohortRequirements( cohort, checkEndAfterStart = TRUE, checkOverlappingEntries = TRUE, checkMissingValues = TRUE, checkInObservation = TRUE, type = "error", call = parent.frame() )checkCohortRequirements( cohort, checkEndAfterStart = TRUE, checkOverlappingEntries = TRUE, checkMissingValues = TRUE, checkInObservation = TRUE, type = "error", call = parent.frame() )
cohort |
|
checkEndAfterStart |
If TRUE a check that all cohort end dates come on or after cohort start date will be performed. |
checkOverlappingEntries |
If TRUE a check that no individuals have overlapping cohort entries will be performed. |
checkMissingValues |
If TRUE a check that there are no missing values in required fields will be performed. |
checkInObservation |
If TRUE a check that cohort entries are within the individuals observation periods will be performed. |
type |
Can be either "error" or "warning". If "error" any check failure will result in an error, whereas if "warning" any check failure will result in a warning. |
call |
The call for which to return the error message. |
An error will be returned if any of the selected checks fail.
Get codelist from a cohort_table object.
cohortCodelist( cohort, cohortId = NULL, codelistType = c("index event", "inclusion criteria", "exit criteria"), type = lifecycle::deprecated(), cohortTable = lifecycle::deprecated() )cohortCodelist( cohort, cohortId = NULL, codelistType = c("index event", "inclusion criteria", "exit criteria"), type = lifecycle::deprecated(), cohortTable = lifecycle::deprecated() )
cohort |
A |
cohortId |
A particular cohort definition id that is present in the cohort table. If NULL the codelists of all cohorts will be retrieved. |
codelistType |
The reason for the codelist. Can be "index event", "inclusion criteria", or "exit criteria". |
type |
deprecated. |
cohortTable |
deprecated. |
A table with the codelists used.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), cohort_end_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )) ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cdm$cohort1 <- newCohortTable(table = cdm$cohort1, cohortCodelistRef = dplyr::tibble( cohort_definition_id = c(1,1,1,2,2), codelist_name =c("disease X", "disease X", "disease X", "disease Y", "disease Y"), concept_id = c(1,2,3,4,5), codelist_type = "index event" )) cohortCodelist(cdm$cohort1, cohortId = 1, codelistType = "index event")library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), cohort_end_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )) ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cdm$cohort1 <- newCohortTable(table = cdm$cohort1, cohortCodelistRef = dplyr::tibble( cohort_definition_id = c(1,1,1,2,2), codelist_name =c("disease X", "disease X", "disease X", "disease Y", "disease Y"), concept_id = c(1,2,3,4,5), codelist_type = "index event" )) cohortCodelist(cdm$cohort1, cohortId = 1, codelistType = "index event")
Required columns for a generated cohort set.
cohortColumns(table, version = "5.3")cohortColumns(table, version = "5.3")
table |
Either |
version |
Version of the OMOP Common Data Model. |
Character vector with the column names
Required columns
library(omopgenerics) cohortColumns("cohort")library(omopgenerics) cohortColumns("cohort")
Get cohort counts from a cohort_table object.
cohortCount(cohort)cohortCount(cohort)
cohort |
A |
A table with the counts.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), cohort_end_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cohortCount(cdm$cohort1)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), cohort_end_date = as.Date(c( "2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01" )), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cohortCount(cdm$cohort1)
Cohort tables that a cdm reference can contain in the OMOP Common Data Model.
cohortTables(version = "5.3")cohortTables(version = "5.3")
version |
Version of the OMOP Common Data Model. |
cohort tables
library(omopgenerics) cohortTables()library(omopgenerics) cohortTables()
Retrieve the cdm reference into a local cdm.
## S3 method for class 'cdm_reference' collect(x, ...)## S3 method for class 'cdm_reference' collect(x, ...)
x |
A cdm_reference object. |
... |
For compatibility; not used. |
A local cdm_reference.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) collect(cdm)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) collect(cdm)
cohort_table object.To collect a cohort_table object.
## S3 method for class 'cohort_table' collect(x, ...)## S3 method for class 'cohort_table' collect(x, ...)
x |
|
... |
For compatibility; not used. |
A data frame with the cohort_table
Provide all combinations of strata levels.
combineStrata(levels, overall = FALSE)combineStrata(levels, overall = FALSE)
levels |
Vector of all strata levels to combine. |
overall |
Whether to provide an empty element |
A vector of all combinations of strata.
combineStrata(character()) combineStrata(character(), overall = TRUE) combineStrata(c("age", "sex"), overall = TRUE) combineStrata(c("age", "sex", "year"))combineStrata(character()) combineStrata(character(), overall = TRUE) combineStrata(c("age", "sex"), overall = TRUE) combineStrata(c("age", "sex", "year"))
Compare the fields of two different OMOP CDM versions
compareOmopTableFields( cdmVersionReference = "5.3", cdmVersionComparator = "5.4" )compareOmopTableFields( cdmVersionReference = "5.3", cdmVersionComparator = "5.4" )
cdmVersionReference |
An OMOP CDM version, it can either be "5.3" or "5.4". |
cdmVersionComparator |
An OMOP CDM version, it can either be "5.3" or "5.4". |
A tibble with two columns: field and change.
library(omopgenerics) compareOmopTableFields("5.3", "5.4")library(omopgenerics) compareOmopTableFields("5.3", "5.4")
Store results in a table.
## S3 method for class 'cdm_table' compute( x, name = NULL, temporary = NULL, overwrite = TRUE, logPrefix = NULL, ... )## S3 method for class 'cdm_table' compute( x, name = NULL, temporary = NULL, overwrite = TRUE, logPrefix = NULL, ... )
x |
Table in the cdm. |
name |
Name to store the table with. |
temporary |
Whether to store table temporarily (TRUE) or permanently (FALSE). |
overwrite |
Whether to overwrite an existing table. |
logPrefix |
Prefix to use when saving a log file. |
... |
For compatibility; not used. |
Reference to a table in the cdm
createIndexes(x, name = NULL)createIndexes(x, name = NULL)
x |
A |
name |
Name(s) of the CDM table(s). |
Whether the process was completed successfully.
Create a log file
createLogFile(logFile = here::here("log_{date}_{time}"))createLogFile(logFile = here::here("log_{date}_{time}"))
logFile |
File path to write logging messages. You can use '{date}' and '{time}' to add the date and time in the log file name. |
Invisible TRUE if logger was created correctly.
library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)
createTableIndex(table, index)createTableIndex(table, index)
table |
A |
index |
Index to be created. |
Whether the index could be created
Drop a table from a cdm object.
dropSourceTable(cdm, name)dropSourceTable(cdm, name)
cdm |
A |
name |
Name(s) of the table(s) to drop. Tidyselect statements are supported. |
The table in the cdm reference.
Drop a table from a cdm object.
dropTable(cdm, name)dropTable(cdm, name)
cdm |
A |
name |
Name(s) of the table(s) to drop Tidyselect statements are supported. |
The cdm reference.
Create an empty achilles table
emptyAchillesTable(cdm, name)emptyAchillesTable(cdm, name)
cdm |
A |
name |
Name of the table to create. |
The cdm_reference with an achilles empty table
library(omopgenerics) cdm <- emptyCdmReference("my_example_cdm") emptyAchillesTable(cdm = cdm, name = "achilles_results")library(omopgenerics) cdm <- emptyCdmReference("my_example_cdm") emptyAchillesTable(cdm = cdm, name = "achilles_results")
Create an empty cdm_reference
emptyCdmReference(cdmName, cdmVersion = NULL)emptyCdmReference(cdmName, cdmVersion = NULL)
cdmName |
Name of the |
cdmVersion |
Version of the OMOP Common Data Model. Supported versions are "5.3" and "5.4". |
An empty cdm_reference
library(omopgenerics) emptyCdmReference(cdmName = "my_example_cdm")library(omopgenerics) emptyCdmReference(cdmName = "my_example_cdm")
codelist object.Empty codelist object.
emptyCodelist()emptyCodelist()
An empty codelist object.
emptyCodelist()emptyCodelist()
codelist object.Empty codelist object.
emptyCodelistWithDetails()emptyCodelistWithDetails()
An empty codelist object.
emptyCodelistWithDetails()emptyCodelistWithDetails()
Empty code search object
emptyCodeSearch(searchStrategy = NULL)emptyCodeSearch(searchStrategy = NULL)
searchStrategy |
The search strategy used to generate the candidate codes. |
An empty code_search object.
Create an empty cohort_table object
emptyCohortTable(cdm, name, overwrite = TRUE)emptyCohortTable(cdm, name, overwrite = TRUE)
cdm |
A |
name |
Name of the table to create. |
overwrite |
Whether to overwrite an existing table. |
The cdm_reference with an empty cohort table
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) cdm <- emptyCohortTable(cdm, "my_empty_cohort") cdm cdm$my_empty_cohort settings(cdm$my_empty_cohort) attrition(cdm$my_empty_cohort) cohortCount(cdm$my_empty_cohort)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) cdm <- emptyCohortTable(cdm, "my_empty_cohort") cdm cdm$my_empty_cohort settings(cdm$my_empty_cohort) attrition(cdm$my_empty_cohort) cohortCount(cdm$my_empty_cohort)
concept_set_expression object.Empty concept_set_expression object.
emptyConceptSetExpression()emptyConceptSetExpression()
An empty concept_set_expression object.
emptyConceptSetExpression()emptyConceptSetExpression()
Create an empty omop table
emptyOmopTable(cdm, name)emptyOmopTable(cdm, name)
cdm |
A |
name |
Name of the table to create. |
The cdm_reference with an empty cohort table
library(omopgenerics) person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) cdm <- emptyOmopTable(cdm, "drug_exposure") cdm$drug_exposurelibrary(omopgenerics) person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) cdm <- emptyOmopTable(cdm, "drug_exposure") cdm$drug_exposure
summarised_result object.Empty summarised_result object.
emptySummarisedResult(settings = NULL)emptySummarisedResult(settings = NULL)
settings |
Tibble/data.frame with the settings of the empty
summarised_result. It has to contain at least |
An empty summarised_result object.
library(omopgenerics) emptySummarisedResult()library(omopgenerics) emptySummarisedResult()
estimate_type column.Choices that can be present in estimate_type column.
estimateTypeChoices()estimateTypeChoices()
A character vector with the options that can be present in
estimate_type column in the summarised_result objects.
library(omopgenerics) estimateTypeChoices()library(omopgenerics) estimateTypeChoices()
existingIndexes(x, name)existingIndexes(x, name)
x |
A |
name |
Name(s) of the CDM table(s). |
A tibble with 3 columns: table_class class of the table,
table_name name of the table, and existing_index index definition.
expectedIndexes(x, name)expectedIndexes(x, name)
x |
A |
name |
Name(s) of the CDM table(s). |
A tibble with 3 columns: table_class class of the table,
table_name name of the table, and expected_index index definition.
Export a codelist object.
exportCodelist(x, path, type = "json")exportCodelist(x, path, type = "json")
x |
A |
path |
Path to where files will be created. |
type |
Type of files to export. Currently 'json' and 'csv' are supported. |
Files with codelists
Export a codelist with details object.
exportCodelistWithDetails(x, path, type = "json")exportCodelistWithDetails(x, path, type = "json")
x |
A |
path |
Path to where files will be created. |
type |
Type of files to export. Currently 'json' and 'csv' are supported. |
Files with codelists with details
code_search object into an Excel spreadsheetexportCodeSearch(codeSearch, file, path = getwd())exportCodeSearch(codeSearch, file, path = getwd())
codeSearch |
A |
file |
Name of the Excel spreadsheet to be created. |
path |
Path where to create the Excel file. |
The code_search object is exported to a file.
Export a concept set expression.
exportConceptSetExpression(x, path, type = "json")exportConceptSetExpression(x, path, type = "json")
x |
A |
path |
Path to where files will be created. |
type |
Type of files to export. Currently 'json' and 'csv' are supported. |
Files with concept set expressions
Export a summarised_result object to a CSV file.
exportSummarisedResult( ..., minCellCount = 5, fileName = "results_{cdm_name}_{date}.csv", path = getwd(), logFile = getOption("omopgenerics.logFile"), logSqlPath = getOption("omopgenerics.log_sql_path"), logExplainPath = lifecycle::deprecated() )exportSummarisedResult( ..., minCellCount = 5, fileName = "results_{cdm_name}_{date}.csv", path = getwd(), logFile = getOption("omopgenerics.logFile"), logSqlPath = getOption("omopgenerics.log_sql_path"), logExplainPath = lifecycle::deprecated() )
... |
A set of summarised_result objects. |
minCellCount |
Minimum count for suppression purposes. |
fileName |
Name of the file that will be created. Use {cdm_name} to refer to the cdmName of the objects and {date} to add the export date. |
path |
Path where the CSV file should be created. It is ignored if fileName is a full file name with a path included. |
logFile |
Path to the log file to export. |
logSqlPath |
Path to the folder that contains the sql logs to export. |
logExplainPath |
deprecated. |
Filter the additional_name-additional_level pair in a summarised_result
filterAdditional(result, ...)filterAdditional(result, ...)
result |
A |
... |
Expressions that return a logical value ( |
A <summarised_result> object with only the rows that satisfy the
specified additional columns.
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = c("cohort1", "cohort2", "cohort3"), "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = c("year", "time_step", "year &&& time_step"), "additional_level" = c("2010", "4", "2015 &&& 5") ) |> newSummarisedResult() x |> filterAdditional(year == "2010")library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = c("cohort1", "cohort2", "cohort3"), "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = c("year", "time_step", "year &&& time_step"), "additional_level" = c("2010", "4", "2015 &&& 5") ) |> newSummarisedResult() x |> filterAdditional(year == "2010")
Filter the group_name-group_level pair in a summarised_result
filterGroup(result, ...)filterGroup(result, ...)
result |
A |
... |
Expressions that return a logical value ( |
A <summarised_result> object with only the rows that satisfy the
specified group.
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = c("cohort_name", "age_group &&& cohort_name", "age_group"), "group_level" = c("my_cohort", ">40 &&& second_cohort", "<40"), "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> filterGroup(cohort_name == "second_cohort")library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = c("cohort_name", "age_group &&& cohort_name", "age_group"), "group_level" = c("my_cohort", ">40 &&& second_cohort", "<40"), "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> filterGroup(cohort_name == "second_cohort")
<summarised_result> automaticallyFilter a <summarised_result> automatically
filterResult(result, ...)filterResult(result, ...)
result |
A |
... |
Expressions that return a logical value. The columns used in the
expressions can be stored in the settings, strata, group, or additional
columns. |
A <summarised_result> object with only the rows that satisfy the
specified filters.
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = "100", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = 1L, "analysis" = "overall" )) x |> filterResult(cohort_name == "my_cohort", sex == "Female")library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "Female", "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = "100", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = 1L, "analysis" = "overall" )) x |> filterResult(cohort_name == "my_cohort", sex == "Female")
<summarised_result> using the settingsFilter a <summarised_result> using the settings
filterSettings(result, ...)filterSettings(result, ...)
result |
A |
... |
Expressions that return a logical value (columns in settings are used to evaluate the expression), and are defined in terms of the variables in .data. If multiple expressions are included, they are combined with the & operator. Only rows for which all conditions evaluate to TRUE are kept. |
A <summarised_result> object with only the result_id rows that
satisfy the specified settings.
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> filterSettings(custom == "A")library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> filterSettings(custom == "A")
Filter the strata_name-strata_level pair in a summarised_result
filterStrata(result, ...)filterStrata(result, ...)
result |
A |
... |
Expressions that return a logical value ( |
A <summarised_result> object with only the rows that satisfy the
specified strata.
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> filterStrata(sex == "Female")library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> filterStrata(sex == "Female")
Get the cohort definition id of a certain name
getCohortId(cohort, cohortName = NULL)getCohortId(cohort, cohortName = NULL)
cohort |
A |
cohortName |
Names of the cohort of interest or a tidyselect expression referring to cohort names. If NULL all cohort names are shown. |
Cohort definition ids
Get the cohort name of a certain cohort definition id
getCohortName(cohort, cohortId = NULL)getCohortName(cohort, cohortId = NULL)
cohort |
A |
cohortId |
Cohort definition id of interest. If NULL all cohort ids are shown. |
Cohort names
Get the column name with the person identifier from a table (either subject_id or person_id), it will throw an error if it contains both or neither.
getPersonIdentifier(x, call = parent.frame())getPersonIdentifier(x, call = parent.frame())
x |
A table. |
call |
Call argument passed to |
Person identifier column.
Identifies and returns the unique values in group_name column.
groupColumns(result)groupColumns(result)
result |
A |
Unique values of the group name column.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> groupColumns() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> groupColumns() }
Import a codelist.
importCodelist(path, type = NULL, recursive = FALSE)importCodelist(path, type = NULL, recursive = FALSE)
path |
Path to a file or directory to import. |
type |
Type of files to import. If |
recursive |
If TRUE and path is a directory, search for files will recurse into directories. |
A codelist
Import a codelist with details.
importCodelistWithDetails(path, type = NULL, recursive = FALSE)importCodelistWithDetails(path, type = NULL, recursive = FALSE)
path |
Path to a file or directory to import. |
type |
Type of files to import. If |
recursive |
If TRUE and path is a directory, search for files will recurse into directories. |
A codelist_with_details object.
code_search object from an Excel spreadsheetimportCodeSearch(path)importCodeSearch(path)
path |
Path to the Excel spreadsheet. |
A code_search object.
Import a concept set expression.
importConceptSetExpression(path, type = NULL, recursive = FALSE)importConceptSetExpression(path, type = NULL, recursive = FALSE)
path |
Path to a file or directory to import. |
type |
Type of files to import. If |
recursive |
If TRUE and path is a directory, search for files will recurse into directories. |
A concept set expression
Import a set of summarised results.
importSummarisedResult(path, recursive = FALSE, ...)importSummarisedResult(path, recursive = FALSE, ...)
path |
Path to directory with CSV files containing summarised results or to a specific CSV file with a summarised result. |
recursive |
If TRUE and path is a directory, search for files will recurse into directories. |
... |
Passed to |
A summarised result
Insert a cdm_reference object to a different source.
insertCdmTo(cdm, to)insertCdmTo(cdm, to)
cdm |
A |
to |
A cdm_source or another cdm_reference, with a valid cdm_source. |
If cdm is not local, it will be collected into memory before
insertion.
The first cdm_reference object inserted to the source.
insertFromSource(cdm, value)insertFromSource(cdm, value)
cdm |
A |
value |
A table that shares source with the cdm_reference object. |
A table in the cdm_reference environment
Insert a table into a cdm object.
insertTable(cdm, name, table, overwrite = TRUE, temporary = FALSE, ...)insertTable(cdm, name, table, overwrite = TRUE, temporary = FALSE, ...)
cdm |
A |
name |
Name of the table to insert. |
table |
Table to insert into the cdm. |
overwrite |
Whether to overwrite an existing table. |
temporary |
Whether to create a temporary table. |
... |
For compatibility; not used. |
The cdm reference. library(omopgenerics) library(dplyr, warn.conflicts = FALSE)
person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm" )
x <- tibble(a = 1)
cdm <- insertTable(cdm = cdm, name = "new_table", table = x)
cdm$new_table
To check whether an object is already suppressed to a certain min cell count.
isResultSuppressed(result, minCellCount = 5)isResultSuppressed(result, minCellCount = 5)
result |
The suppressed result to check |
minCellCount |
Minimum count of records used when suppressing |
Warning or message with check result
x <- dplyr::tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() isResultSuppressed(x)x <- dplyr::tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() isResultSuppressed(x)
Check if a table is empty or not
isTableEmpty(table)isTableEmpty(table)
table |
a table |
Boolean to indicate if a cdm_table is empty (TRUE or FALSE).
List tables that can be accessed through a cdm object.
listSourceTables(cdm)listSourceTables(cdm)
cdm |
A |
A character vector with the names of tables.
The message is written to the logFile and displayed in the console, if
logFile does not exist the message is only displayed in the console.
logMessage( message = "Start logging file", logFile = getOption("omopgenerics.logFile") )logMessage( message = "Start logging file", logFile = getOption("omopgenerics.logFile") )
message |
Message to log. |
logFile |
File path to write logging messages. Create a logFile with
|
Invisible TRUE if the logging message is written to a log file.
library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)
Create an achilles table from a cdm_table.
newAchillesTable(table, version = "5.3", cast = FALSE)newAchillesTable(table, version = "5.3", cast = FALSE)
table |
A |
version |
Version of the OMOP Common Data Model. |
cast |
Whether to cast columns to the correct type. |
An achilles_table object
cdm_reference objects constructorcdm_reference objects constructor
newCdmReference(tables, cdmName, cdmVersion = NULL, .softValidation = FALSE)newCdmReference(tables, cdmName, cdmVersion = NULL, .softValidation = FALSE)
tables |
List of tables that are part of the OMOP Common Data Model reference. |
cdmName |
Name of the |
cdmVersion |
Version of the OMOP Common Data Model. Supported versions are "5.3" and "5.4". |
.softValidation |
Whether to perform a soft validation of consistency. If set to FALSE, non overlapping observation periods are ensured. |
A cdm_reference object.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdmTables <- list( "person" = tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) |> newCdmTable(newLocalSource(), "person"), "observation_period" = tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) |> newCdmTable(newLocalSource(), "observation_period") ) cdm <- newCdmReference(tables = cdmTables, cdmName = "mock") cdmlibrary(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdmTables <- list( "person" = tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) |> newCdmTable(newLocalSource(), "person"), "observation_period" = tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) |> newCdmTable(newLocalSource(), "observation_period") ) cdm <- newCdmReference(tables = cdmTables, cdmName = "mock") cdm
Create a cdm source object.
newCdmSource(src, sourceType)newCdmSource(src, sourceType)
src |
Source for a cdm object. |
sourceType |
Type of the source object. |
A validated cdm source object.
Create an cdm table.
newCdmTable(table, src, name)newCdmTable(table, src, name)
table |
A table that is part of a cdm. |
src |
The source of the table. |
name |
The name of the table. |
A cdm_table object
'codelist' object constructor
newCodelist(x, cdm = NULL)newCodelist(x, cdm = NULL)
x |
A named list where each element contains a vector of concept IDs. |
cdm |
A |
A codelist object.
'codelist' object constructor
newCodelistWithDetails(x, cdm = NULL)newCodelistWithDetails(x, cdm = NULL)
x |
A named list where each element contains a tibble with the column concept_id |
cdm |
A |
A codelist object.
code_search objectnewCodeSearch(codes, searchStrategy)newCodeSearch(codes, searchStrategy)
codes |
A tibble with concept ids. It must contain "concept_id", "found_from", "concept_name", "vocabulary_version", "domain_id", "vocabulary_id", "concept_class_id", "standard_concept", "concept_code", "valid_start_date", "valid_end_date" and "invalid_reason" as columns. |
searchStrategy |
A tibble with the search strategy used to derive the codes. It must contain "strategy_id", "strategy_name" and "strategy_value" as columns. |
A code_search object.
cohort_table objects constructor.cohort_table objects constructor.
newCohortTable( table, cohortSetRef = attr(table, "cohort_set"), cohortAttritionRef = attr(table, "cohort_attrition"), cohortCodelistRef = attr(table, "cohort_codelist"), .softValidation = FALSE )newCohortTable( table, cohortSetRef = attr(table, "cohort_set"), cohortAttritionRef = attr(table, "cohort_attrition"), cohortCodelistRef = attr(table, "cohort_codelist"), .softValidation = FALSE )
table |
cdm_table object with at least: cohort_definition_id, subject_id, cohort_start_date, cohort_end_date. |
cohortSetRef |
Table with at least: cohort_definition_id, cohort_name |
cohortAttritionRef |
Table with at least: cohort_definition_id, number_subjects, number_records, reason_id, reason, excluded_subjects, excluded_records. |
cohortCodelistRef |
Table with at least: cohort_definition_id, codelist_name, concept_id and codelist_type. |
.softValidation |
Whether to perform a soft validation of consistency. If set to FALSE four additional checks will be performed: 1) a check that cohort end date is not before cohort start date, 2) a check that there are no missing values in required columns, 3) a check that cohort duration is all within observation period, and 4) that there are no overlapping cohort entries |
A cohort_table object
person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort1 <- dplyr::tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2020-01-10") ) cdm <- cdmFromTables( tables = list( "person" = person, "observation_period" = observation_period, "cohort1" = cohort1 ), cdmName = "test" ) cdm cdm$cohort1 <- newCohortTable(table = cdm$cohort1) cdm settings(cdm$cohort1) attrition(cdm$cohort1) cohortCount(cdm$cohort1)person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort1 <- dplyr::tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2020-01-10") ) cdm <- cdmFromTables( tables = list( "person" = person, "observation_period" = observation_period, "cohort1" = cohort1 ), cdmName = "test" ) cdm cdm$cohort1 <- newCohortTable(table = cdm$cohort1) cdm settings(cdm$cohort1) attrition(cdm$cohort1) cohortCount(cdm$cohort1)
'concept_set_expression' object constructor
newConceptSetExpression(x, cdm = NULL)newConceptSetExpression(x, cdm = NULL)
x |
a named list of tibbles, each of which containing concept set definitions |
cdm |
A |
A concept_set_expression
A new local source for the cdm
newLocalSource()newLocalSource()
A list in the format of a cdm source.
library(omopgenerics) newLocalSource()library(omopgenerics) newLocalSource()
Create an omop table from a cdm table.
newOmopTable(table, version = "5.3", cast = FALSE)newOmopTable(table, version = "5.3", cast = FALSE)
table |
A |
version |
Version of the OMOP Common Data Model. |
cast |
Whether to cast columns to the correct type. |
An omop_table object
This source can be used for cdm_reference objects that should allow reading
existing CDM tables, but should not allow creating, computing, inserting,
reading from, or dropping source tables.
newReadOnlySource()newReadOnlySource()
A read-only source in the format of a cdm source.
library(omopgenerics) newReadOnlySource()library(omopgenerics) newReadOnlySource()
summarised_result object constructorsummarised_result object constructor
newSummarisedResult(x, settings = attr(x, "settings"))newSummarisedResult(x, settings = attr(x, "settings"))
x |
Table. |
settings |
Settings for the summarised_result object. |
A summarised_result object
library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "cprd", "group_name" = "cohort_name", "group_level" = "acetaminophen", "strata_name" = "sex &&& age_group", "strata_level" = c("male &&& <40", "male &&& >=40"), "variable_name" = "number_subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("5", "15"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x settings(x) summary(x) x <- tibble( "result_id" = 1L, "cdm_name" = "cprd", "group_name" = "cohort_name", "group_level" = "acetaminophen", "strata_name" = "sex &&& age_group", "strata_level" = c("male &&& <40", "male &&& >=40"), "variable_name" = "number_subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("5", "15"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( result_id = 1L, result_type = "custom_summary", mock = TRUE, value = 5 )) x settings(x) summary(x)library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = "cprd", "group_name" = "cohort_name", "group_level" = "acetaminophen", "strata_name" = "sex &&& age_group", "strata_level" = c("male &&& <40", "male &&& >=40"), "variable_name" = "number_subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("5", "15"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x settings(x) summary(x) x <- tibble( "result_id" = 1L, "cdm_name" = "cprd", "group_name" = "cohort_name", "group_level" = "acetaminophen", "strata_name" = "sex &&& age_group", "strata_level" = c("male &&& <40", "male &&& >=40"), "variable_name" = "number_subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("5", "15"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( result_id = 1L, result_type = "custom_summary", mock = TRUE, value = 5 )) x settings(x) summary(x)
cdm_table has.Count the number of records that a cdm_table has.
numberRecords(x)numberRecords(x)
x |
A cdm_table. |
An integer with the number of records in the table.
person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) numberRecords(cdm$observation_period)person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) numberRecords(cdm$observation_period)
cdm_table has.Count the number of subjects that a cdm_table has.
numberSubjects(x)numberSubjects(x)
x |
A cdm_table. |
An integer with the number of subjects in the table.
person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) numberSubjects(cdm$observation_period)person <- dplyr::tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- dplyr::tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) numberSubjects(cdm$observation_period)
Required columns that the standard tables in the OMOP Common Data Model must have.
omopColumns( table, field = NULL, version = "5.3", onlyRequired = lifecycle::deprecated() )omopColumns( table, field = NULL, version = "5.3", onlyRequired = lifecycle::deprecated() )
table |
Table to see required columns. |
field |
Name of the specific field. |
version |
Version of the OMOP Common Data Model. |
onlyRequired |
deprecated |
Character vector with the column names
library(omopgenerics) omopColumns("person")library(omopgenerics) omopColumns("person")
Check or set the OMOP_DATA_FOLDER where the OMOP related data is stored.
omopDataFolder(path = NULL)omopDataFolder(path = NULL)
path |
Path to a folder to store the OMOP related data. If NULL the
current |
The OMOP data folder.
omopDataFolder() omopDataFolder(file.path(tempdir(), "OMOP_DATA")) omopDataFolder()omopDataFolder() omopDataFolder(file.path(tempdir(), "OMOP_DATA")) omopDataFolder()
Return a table of omop cdm field information
omopTableFields(cdmVersion = "5.3")omopTableFields(cdmVersion = "5.3")
cdmVersion |
cdm version of the omop cdm. |
A tibble containing information on all the different fields in omop cdm.
Standard tables that a cdm reference can contain in the OMOP Common Data Model.
omopTables(version = "5.3")omopTables(version = "5.3")
version |
Version of the OMOP Common Data Model. |
Standard tables
library(omopgenerics) omopTables()library(omopgenerics) omopTables()
Pivot the estimates as new columns in result table.
pivotEstimates(result, pivotEstimatesBy = "estimate_name", nameStyle = NULL)pivotEstimates(result, pivotEstimatesBy = "estimate_name", nameStyle = NULL)
result |
A |
pivotEstimatesBy |
Names from which to pivot the estimate values wider. If NULL the table will not be pivoted. |
nameStyle |
Name style (glue package specifications) to customise names when pivoting estimates. If NULL standard tidyr::pivot_wider formatting will be used. |
A tibble.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> pivotEstimates() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = 1L, "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() x |> pivotEstimates() }
Print a CDM reference object
## S3 method for class 'cdm_reference' print(x, ...)## S3 method for class 'cdm_reference' print(x, ...)
x |
A cdm_reference object |
... |
For compatibility; not used. |
Invisibly returns the input
library(omopgenerics) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) print(cdm)library(omopgenerics) cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) print(cdm)
Print a code search
## S3 method for class 'code_search' print(x, ...)## S3 method for class 'code_search' print(x, ...)
x |
A |
... |
For compatibility with the generic. |
Invisibly returns the input.
Print a codelist
## S3 method for class 'codelist' print(x, ...)## S3 method for class 'codelist' print(x, ...)
x |
A |
... |
For compatibility; not used. |
Invisibly returns the input
codes <- list("disease X" = c(1, 2, 3), "disease Y" = c(4, 5)) codes <- newCodelist(codes) print(codes)codes <- list("disease X" = c(1, 2, 3), "disease Y" = c(4, 5)) codes <- newCodelist(codes) print(codes)
Print a codelist with details
## S3 method for class 'codelist_with_details' print(x, ...)## S3 method for class 'codelist_with_details' print(x, ...)
x |
A |
... |
For compatibility; not used. |
Invisibly returns the input
codes <- list("disease X" = dplyr::tibble( concept_id = c(1, 2, 3), other = c("a", "b", "c") )) codes <- newCodelistWithDetails(codes) print(codes)codes <- list("disease X" = dplyr::tibble( concept_id = c(1, 2, 3), other = c("a", "b", "c") )) codes <- newCodelistWithDetails(codes) print(codes)
Print a concept set expression
## S3 method for class 'concept_set_expression' print(x, ...)## S3 method for class 'concept_set_expression' print(x, ...)
x |
A |
... |
For compatibility; not used. |
Invisibly returns the input
asthma_cs <- list( "asthma_narrow" = dplyr::tibble( "concept_id" = 1, "excluded" = FALSE, "descendants" = TRUE, "mapped" = FALSE ), "asthma_broad" = dplyr::tibble( "concept_id" = c(1, 2), "excluded" = FALSE, "descendants" = TRUE, "mapped" = FALSE ) ) asthma_cs <- newConceptSetExpression(asthma_cs) print(asthma_cs)asthma_cs <- list( "asthma_narrow" = dplyr::tibble( "concept_id" = 1, "excluded" = FALSE, "descendants" = TRUE, "mapped" = FALSE ), "asthma_broad" = dplyr::tibble( "concept_id" = c(1, 2), "excluded" = FALSE, "descendants" = TRUE, "mapped" = FALSE ) ) asthma_cs <- newConceptSetExpression(asthma_cs) print(asthma_cs)
Read a table from the cdm_source and add it to the cdm.
readSourceTable(cdm, name)readSourceTable(cdm, name)
cdm |
A |
name |
Name of a table to read in the cdm_source space. Tidyselect statements are supported. |
A cdm_reference with new table.
Update cohort attrition.
recordCohortAttrition(cohort, reason, cohortId = NULL)recordCohortAttrition(cohort, reason, cohortId = NULL)
cohort |
A |
reason |
A character string. |
cohortId |
Cohort definition id of the cohort to update attrition. If NULL all cohort_definition_id are updated. |
cohort_table with updated attrition.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), cohort_end_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cdm$cohort1 attrition(cdm$cohort1) cdm$cohort1 <- cdm$cohort1 |> group_by(cohort_definition_id, subject_id) |> filter(cohort_start_date == min(cohort_start_date)) |> ungroup() |> compute(name = "cohort1", temporary = FALSE) |> recordCohortAttrition("Restrict to first observation") cdm$cohort1 attrition(cdm$cohort1)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = c(1, 1, 1, 2), subject_id = 1, cohort_start_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), cohort_end_date = as.Date(c("2020-01-01", "2021-01-01", "2022-01-01", "2022-01-01")), ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "my_example_cdm", cohortTables = list("cohort1" = cohort) ) cdm$cohort1 attrition(cdm$cohort1) cdm$cohort1 <- cdm$cohort1 |> group_by(cohort_definition_id, subject_id) |> filter(cohort_start_date == min(cohort_start_date)) |> ungroup() |> compute(name = "cohort1", temporary = FALSE) |> recordCohortAttrition("Restrict to first observation") cdm$cohort1 attrition(cdm$cohort1)
Required columns that the result tables must have.
resultColumns(table = "summarised_result")resultColumns(table = "summarised_result")
table |
Table to see required columns. |
Required columns
library(omopgenerics) resultColumns()library(omopgenerics) resultColumns()
Check if different package versions are used for a summarised_result object
resultPackageVersion(result)resultPackageVersion(result)
result |
A summarised_result object. |
A summarised_result object.
result_type(s) defined in a certain packageGet the result_type(s) defined in a certain package
resultType(pkg = NULL)resultType(pkg = NULL)
pkg |
A character vector of the packages of interest |
A named (package) list of the result_type registered in each package.
library(omopgenerics) resultType()library(omopgenerics) resultType()
code_search
searchStrategy(codeSearch)searchStrategy(codeSearch)
codeSearch |
A |
A search strategy tibble.
Get settings from an object.
settings(x)settings(x)
x |
Object |
A table with the settings of the object.
Get cohort settings from a cohort_table object.
## S3 method for class 'cohort_table' settings(x)## S3 method for class 'cohort_table' settings(x)
x |
A cohort_table object. |
A table with the details of the cohort settings.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2012-01-01") ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("my_cohort" = cohort) ) settings(cdm$my_cohort) cdm$my_cohort <- cdm$my_cohort |> newCohortTable(cohortSetRef = tibble( cohort_definition_id = 1, cohort_name = "new_name" )) settings(cdm$my_cohort)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2012-01-01") ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("my_cohort" = cohort) ) settings(cdm$my_cohort) cdm$my_cohort <- cdm$my_cohort |> newCohortTable(cohortSetRef = tibble( cohort_definition_id = 1, cohort_name = "new_name" )) settings(cdm$my_cohort)
Get settings from a summarised_result object.
## S3 method for class 'summarised_result' settings(x)## S3 method for class 'summarised_result' settings(x)
x |
A summarised_result object. |
A table with the settings.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2012-01-01") ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("my_cohort" = cohort) ) result <- summary(cdm$my_cohort) settings(result)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cohort <- tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2012-01-01") ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("my_cohort" = cohort) ) result <- summary(cdm$my_cohort) settings(result)
<summarised_result>
Identifies and returns the columns of the settings table
obtained by using settings() in a <summarised_result> object.
settingsColumns(result, metadata = FALSE)settingsColumns(result, metadata = FALSE)
result |
A |
metadata |
Whether to include metadata columns in settings or not. |
Vector with names of the settings columns
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> settingsColumns() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> settingsColumns() }
Get the source type of an object.
sourceType(x)sourceType(x)
x |
Object for which to get the source type. |
A character vector that defines the type of cdm_source.
Pivots the input dataframe so the values of the column additional_name are transformed into columns that contain values from the additional_level column.
splitAdditional(result, keep = FALSE, fill = "overall")splitAdditional(result, keep = FALSE, fill = "overall")
result |
A dataframe with at least the columns additional_name and additional_level. |
keep |
Whether to keep the original group_name and group_level columns. |
fill |
Optionally, a character that specifies what value should be filled in with when missing. |
A dataframe.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitAdditional() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitAdditional() }
Pivots the input dataframe so any pair name-level columns are transformed into columns (name) that contain values from the corresponding level.
splitAll(result, keep = FALSE, fill = "overall", exclude = "variable")splitAll(result, keep = FALSE, fill = "overall", exclude = "variable")
result |
A data.frame. |
keep |
Whether to keep the original name-level columns. |
fill |
A character that specifies what value should be filled in when missing. |
exclude |
Name of a column pair to exclude. |
A dataframe with group, strata and additional as columns.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitAll() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitAll() }
Pivots the input dataframe so the values of the column group_name are transformed into columns that contain values from the group_level column.
splitGroup(result, keep = FALSE, fill = "overall")splitGroup(result, keep = FALSE, fill = "overall")
result |
A dataframe with at least the columns group_name and group_level. |
keep |
Whether to keep the original group_name and group_level columns. |
fill |
Optionally, a character that specifies what value should be filled in with when missing. |
A dataframe.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitGroup() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitGroup() }
Pivots the input dataframe so the values of the column strata_name are transformed into columns that contain values from the strata_level column.
splitStrata(result, keep = FALSE, fill = "overall")splitStrata(result, keep = FALSE, fill = "overall")
result |
A dataframe with at least the columns strata_name and strata_level. |
keep |
Whether to keep the original group_name and group_level columns. |
fill |
Optionally, a character that specifies what value should be filled in with when missing. |
A dataframe.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitStrata() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> splitStrata() }
statusIndexes(x, name = NULL)statusIndexes(x, name = NULL)
x |
A |
name |
Name(s) of the CDM table(s). |
A tibble with 3 columns: table_class class of the table,
table_name name of the table, index index definition, and index_status
status of the index, either: 'missing', 'extra', 'present'.
Identifies and returns the unique values in strata_name column.
strataColumns(result)strataColumns(result)
result |
A |
Unique values of the strata name column.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> strataColumns() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> strataColumns() }
summarised_result object.Summarise and extract the information of a log file into a
summarised_result object.
summariseLogFile( logFile = getOption("omopgenerics.logFile"), cdmName = "unknown" )summariseLogFile( logFile = getOption("omopgenerics.logFile"), cdmName = "unknown" )
logFile |
File path to the log file to summarise. Create a logFile with
|
cdmName |
Name of the cdm for the |
A summarised_result with the information from the log file.
library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)library(dplyr) logFile <- tempfile(pattern = "log_{date}_{time}", fileext = ".txt") createLogFile(logFile = logFile) logMessage("Starting analysis") 1 + 1 logMessage("Analysis finished") res <- summariseLogFile() glimpse(res) tidy(res)
Summarise a cdm reference
## S3 method for class 'cdm_reference' summary(object, ...)## S3 method for class 'cdm_reference' summary(object, ...)
object |
A cdm reference object. |
... |
For compatibility; not used. |
A summarised_result object with a summary of the data contained in the cdm.
library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) summary(cdm)library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) summary(cdm)
cdm_source objectSummarise a cdm_source object
## S3 method for class 'cdm_source' summary(object, ...)## S3 method for class 'cdm_source' summary(object, ...)
object |
A generated cohort set object. |
... |
For compatibility; not used. |
A list of properties of the cdm_source object.
summary(newLocalSource())summary(newLocalSource())
Summarise a generated cohort set
## S3 method for class 'cohort_table' summary(object, ...)## S3 method for class 'cohort_table' summary(object, ...)
object |
A cdm source object. |
... |
For compatibility; not used. |
A summarised_result object with a summary of a cohort_table.
library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("cohort1" = tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") )) ) summary(cdm$cohort1)library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test", cohortTables = list("cohort1" = tibble( cohort_definition_id = 1, subject_id = 1, cohort_start_date = as.Date("2010-01-01"), cohort_end_date = as.Date("2010-01-05") )) ) summary(cdm$cohort1)
Summarise a summarised_result
## S3 method for class 'summarised_result' summary(object, ...)## S3 method for class 'summarised_result' summary(object, ...)
object |
A summarised_result object. |
... |
For compatibility; not used. |
A summary of the result_types contained in a summarised_result object.
library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) result <- summary(cdm) summary(result)library(dplyr, warn.conflicts = FALSE) person <- tibble( person_id = 1, gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ) observation_period <- tibble( observation_period_id = 1, person_id = 1, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) cdm <- cdmFromTables( tables = list("person" = person, "observation_period" = observation_period), cdmName = "test" ) result <- summary(cdm) summary(result)
Function to suppress counts in result objects
suppress(result, minCellCount = 5)suppress(result, minCellCount = 5)
result |
Result object |
minCellCount |
Minimum count of records to report results. |
Table with suppressed counts
Function to suppress counts in result objects
## S3 method for class 'summarised_result' suppress(result, minCellCount = 5)## S3 method for class 'summarised_result' suppress(result, minCellCount = 5)
result |
summarised_result object. |
minCellCount |
Minimum count of records to report results. |
summarised_result with suppressed counts.
library(dplyr, warn.conflicts = FALSE) library(omopgenerics) my_result <- tibble( "result_id" = "1", "cdm_name" = "mock", "result_type" = "summarised_characteristics", "package_name" = "omopgenerics", "package_version" = as.character(utils::packageVersion("omopgenerics")), "group_name" = "overall", "group_level" = "overall", "strata_name" = c(rep("overall", 6), rep("sex", 3)), "strata_level" = c(rep("overall", 6), "male", "female", "female"), "variable_name" = c( "number records", "age_group", "age_group", "age_group", "age_group", "my_variable", "number records", "age_group", "age_group" ), "variable_level" = c( NA, "<50", "<50", ">=50", ">=50", NA, NA, "<50", "<50" ), "estimate_name" = c( "count", "count", "percentage", "count", "percentage", "random", "count", "count", "percentage" ), "estimate_type" = c( "integer", "integer", "percentage", "integer", "percentage", "numeric", "integer", "integer", "percentage" ), "estimate_value" = c("10", "5", "50", "3", "30", "1", "3", "12", "6"), "additional_name" = "overall", "additional_level" = "overall" ) my_result <- newSummarisedResult(my_result) my_result |> glimpse() my_result <- suppress(my_result, minCellCount = 5) my_result |> glimpse()library(dplyr, warn.conflicts = FALSE) library(omopgenerics) my_result <- tibble( "result_id" = "1", "cdm_name" = "mock", "result_type" = "summarised_characteristics", "package_name" = "omopgenerics", "package_version" = as.character(utils::packageVersion("omopgenerics")), "group_name" = "overall", "group_level" = "overall", "strata_name" = c(rep("overall", 6), rep("sex", 3)), "strata_level" = c(rep("overall", 6), "male", "female", "female"), "variable_name" = c( "number records", "age_group", "age_group", "age_group", "age_group", "my_variable", "number records", "age_group", "age_group" ), "variable_level" = c( NA, "<50", "<50", ">=50", ">=50", NA, NA, "<50", "<50" ), "estimate_name" = c( "count", "count", "percentage", "count", "percentage", "random", "count", "count", "percentage" ), "estimate_type" = c( "integer", "integer", "percentage", "integer", "percentage", "numeric", "integer", "integer", "percentage" ), "estimate_value" = c("10", "5", "50", "3", "30", "1", "3", "12", "6"), "additional_name" = "overall", "additional_level" = "overall" ) my_result <- newSummarisedResult(my_result) my_result |> glimpse() my_result <- suppress(my_result, minCellCount = 5) my_result |> glimpse()
cdm_table.Get the table name of a cdm_table.
tableName(table)tableName(table)
table |
A |
A character with the name.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) tableName(cdm$person)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) tableName(cdm$person)
cdm_table.Get the table source of a cdm_table.
tableSource(table)tableSource(table)
table |
A |
A cdm_source object.
library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) tableSource(cdm$person)library(omopgenerics) library(dplyr, warn.conflicts = FALSE) cdm <- cdmFromTables( tables = list( "person" = tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) tableSource(cdm$person)
<summarised_result> object into a tidy tibble
Provides tools for obtaining a tidy version of a
<summarised_result> object.
This tidy version will include the settings as columns, estimate_value will
be pivoted into columns using estimate_name as names, and group, strata,
and additional will be split.
## S3 method for class 'summarised_result' tidy(x, ...)## S3 method for class 'summarised_result' tidy(x, ...)
x |
A |
... |
For compatibility; not used. |
A tibble.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> tidy() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> tidy() }
<summarised_result>
Identifies and returns the columns that the tidy version of the
<summarised_result> will have.
tidyColumns(result)tidyColumns(result)
result |
A |
Table columns after applying tidy() function to a
<summarised_result>.
{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> tidyColumns() }{ library(dplyr) library(omopgenerics) x <- tibble( "result_id" = as.integer(c(1, 2)), "cdm_name" = c("cprd", "eunomia"), "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = "sex", "strata_level" = "male", "variable_name" = "Age group", "variable_level" = "10 to 50", "estimate_name" = "count", "estimate_type" = "numeric", "estimate_value" = "5", "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult(settings = tibble( "result_id" = c(1, 2), "custom" = c("A", "B") )) x x |> tidyColumns() }
Create a temporary prefix for tables that contains a unique prefix that starts with tmp.
tmpPrefix()tmpPrefix()
A temporary prefix.
library(omopgenerics) tmpPrefix()library(omopgenerics) tmpPrefix()
Convert a character vector to snake case
toSnakeCase(x)toSnakeCase(x)
x |
Character vector to convert |
A snake_case vector
toSnakeCase("myVariable") toSnakeCase(c("cohort1", "Cohort22b"))toSnakeCase("myVariable") toSnakeCase(c("cohort1", "Cohort22b"))
Create a <summarised_result> object from a data.frame, given a set of specifications.
transformToSummarisedResult( x, group = character(), strata = character(), additional = character(), estimates = character(), settings = character() )transformToSummarisedResult( x, group = character(), strata = character(), additional = character(), estimates = character(), settings = character() )
x |
A data.frame. |
group |
Columns in x to be used in group_name-group_level formatting. |
strata |
Columns in x to be used in strata_name-strata_level formatting. |
additional |
Columns in x to be used in additional_name-additional_level formatting. |
estimates |
Columns in x to be formatted into: estimate_name-estimate_type-estimate_value. |
settings |
Columns in x that form the settings of the <summarised_result> object. |
A <summarised_result> object.
x <- dplyr::tibble( cohort_name = c("cohort1", "cohort2"), variable_name = "age", mean = c(50, 45.3), median = c(55L, 44L) ) transformToSummarisedResult( x = x, group = c("cohort_name"), estimates = c("mean", "median") )x <- dplyr::tibble( cohort_name = c("cohort1", "cohort2"), variable_name = "age", mean = c(50, 45.3), median = c(55L, 44L) ) transformToSummarisedResult( x = x, group = c("cohort_name"), estimates = c("mean", "median") )
Get a unique Identifier with a certain number of characters and a prefix.
uniqueId(n = 1, exclude = character(), nChar = 3, prefix = "id_")uniqueId(n = 1, exclude = character(), nChar = 3, prefix = "id_")
n |
Number of identifiers. |
exclude |
Columns to exclude. |
nChar |
Number of characters. |
prefix |
A prefix for the identifiers. |
A character vector with n unique identifiers.
Create a unique table name
uniqueTableName(prefix = "")uniqueTableName(prefix = "")
prefix |
Prefix for the table names. |
A string that can be used as a dbplyr temp table name
library(omopgenerics) uniqueTableName()library(omopgenerics) uniqueTableName()
Unites targeted table columns into additional_name-additional_level columns.
uniteAdditional( x, cols = character(0), keep = FALSE, ignore = c(NA, "overall") )uniteAdditional( x, cols = character(0), keep = FALSE, ignore = c(NA, "overall") )
x |
Tibble or dataframe. |
cols |
Columns to aggregate. |
keep |
Whether to keep the original columns. |
ignore |
Level values to ignore. |
A tibble with the new columns.
x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteAdditional(c("sex", "age_group"))x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteAdditional(c("sex", "age_group"))
Unites targeted table columns into group_name-group_level columns.
uniteGroup(x, cols = character(0), keep = FALSE, ignore = c(NA, "overall"))uniteGroup(x, cols = character(0), keep = FALSE, ignore = c(NA, "overall"))
x |
Tibble or dataframe. |
cols |
Columns to aggregate. |
keep |
Whether to keep the original columns. |
ignore |
Level values to ignore. |
A tibble with the new columns.
x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteGroup(c("sex", "age_group"))x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteGroup(c("sex", "age_group"))
Unites targeted table columns into strata_name-strata_level columns.
uniteStrata(x, cols = character(0), keep = FALSE, ignore = c(NA, "overall"))uniteStrata(x, cols = character(0), keep = FALSE, ignore = c(NA, "overall"))
x |
Tibble or dataframe. |
cols |
Columns to aggregate. |
keep |
Whether to keep the original columns. |
ignore |
Level values to ignore. |
A tibble with the new columns.
x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteStrata(c("sex", "age_group"))x <- dplyr::tibble( variable = "number subjects", value = c(10, 15, 40, 78), sex = c("Male", "Female", "Male", "Female"), age_group = c("<40", ">40", ">40", "<40") ) x |> uniteStrata(c("sex", "age_group"))
Validate if a cdm_table is a valid achilles table.
validateAchillesTable( table, version = NULL, cast = FALSE, empty = TRUE, nm = deparse1(substitute(table), backtick = TRUE), call = parent.frame() )validateAchillesTable( table, version = NULL, cast = FALSE, empty = TRUE, nm = deparse1(substitute(table), backtick = TRUE), call = parent.frame() )
table |
A cdm_table to validate. |
version |
Version of the OMOP Common Data Model. |
cast |
Whether to cast columns to the correct type. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
invisible achilles table
Validate the ageGroup argument. It must be a list of two integerish numbers lower age and upper age, both of the must be greater or equal to 0 and lower age must be lower or equal to the upper age. If not named automatic names will be given in the output list.
validateAgeGroupArgument( ageGroup, multipleAgeGroup = TRUE, overlap = FALSE, null = TRUE, empty = TRUE, ageGroupName = "age_group", nm = deparse1(substitute(ageGroup), backtick = TRUE), call = parent.frame() )validateAgeGroupArgument( ageGroup, multipleAgeGroup = TRUE, overlap = FALSE, null = TRUE, empty = TRUE, ageGroupName = "age_group", nm = deparse1(substitute(ageGroup), backtick = TRUE), call = parent.frame() )
ageGroup |
age group in a list. |
multipleAgeGroup |
Allow multiple age groups. |
overlap |
allow overlapping ageGroup. |
null |
null age group allowed true or false. |
empty |
Whether it can be empty. |
ageGroupName |
Name of the default age group. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
validate ageGroup
validateAgeGroupArgument(list(c(0, 39), c(40, Inf)))validateAgeGroupArgument(list(c(0, 39), c(40, Inf)))
Validate if an object in a valid cdm_reference.
validateCdmArgument( cdm, checkOverlapObservation = FALSE, checkStartBeforeEndObservation = FALSE, checkPlausibleObservationDates = FALSE, checkPerson = FALSE, requiredTables = character(), empty = TRUE, validation = "error", nm = deparse1(substitute(cdm), backtick = TRUE), call = parent.frame() )validateCdmArgument( cdm, checkOverlapObservation = FALSE, checkStartBeforeEndObservation = FALSE, checkPlausibleObservationDates = FALSE, checkPerson = FALSE, requiredTables = character(), empty = TRUE, validation = "error", nm = deparse1(substitute(cdm), backtick = TRUE), call = parent.frame() )
cdm |
A |
checkOverlapObservation |
TRUE to perform check on no overlap observation period |
checkStartBeforeEndObservation |
TRUE to perform check on correct observational start and end date |
checkPlausibleObservationDates |
TRUE to perform check that there are no implausible observation period start dates (before 1800-01-01) or end dates (after the current date) |
checkPerson |
TRUE to perform check on person id in all clinical table are in person table |
requiredTables |
Name of tables that are required to be part of the cdm_reference object. |
empty |
Whether it can be empty. |
validation |
How to perform validation: "error", "warning". |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
A cdm_reference object
cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) validateCdmArgument(cdm)cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cdmName = "mock" ) validateCdmArgument(cdm)
Validate if a table is a valid cdm_table object.
validateCdmTable( table, name = NULL, empty = TRUE, nm = deparse1(substitute(table), backtick = TRUE), call = parent.frame() )validateCdmTable( table, name = NULL, empty = TRUE, nm = deparse1(substitute(table), backtick = TRUE), call = parent.frame() )
table |
Object to validate. |
name |
If we want to validate that the table has a specific name. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
The table or an error message.
Validate a cohort table input.
validateCohortArgument( cohort, checkEndAfterStart = FALSE, checkOverlappingEntries = FALSE, checkMissingValues = FALSE, checkInObservation = FALSE, checkAttributes = FALSE, checkPermanentTable = FALSE, dropExtraColumns = FALSE, empty = TRUE, validation = "error", nm = deparse1(substitute(cohort), backtick = TRUE), call = parent.frame() )validateCohortArgument( cohort, checkEndAfterStart = FALSE, checkOverlappingEntries = FALSE, checkMissingValues = FALSE, checkInObservation = FALSE, checkAttributes = FALSE, checkPermanentTable = FALSE, dropExtraColumns = FALSE, empty = TRUE, validation = "error", nm = deparse1(substitute(cohort), backtick = TRUE), call = parent.frame() )
cohort |
Object to be validated as a valid cohort input. |
checkEndAfterStart |
If TRUE a check that all cohort end dates come on or after cohort start date will be performed. |
checkOverlappingEntries |
If TRUE a check that no individuals have overlapping cohort entries will be performed. |
checkMissingValues |
If TRUE a check that there are no missing values in required fields will be performed. |
checkInObservation |
If TRUE a check that cohort entries are within the individuals observation periods will be performed. |
checkAttributes |
Whether to check if attributes are present and populated correctly. |
checkPermanentTable |
Whether to check if the table has to be a permanent table. |
dropExtraColumns |
Whether to drop extra columns that are not the required ones. |
empty |
Whether it can be empty. |
validation |
How to perform validation: "error", "warning". |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cohortTables = list( cohort = dplyr::tibble( cohort_definition_id = 1L, subject_id = 1L, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2021-02-10") ) ), cdmName = "mock" ) validateCohortArgument(cdm$cohort)cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cohortTables = list( cohort = dplyr::tibble( cohort_definition_id = 1L, subject_id = 1L, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2021-02-10") ) ), cdmName = "mock" ) validateCohortArgument(cdm$cohort)
validateCohortIdArgument({{cohortId}}, cohort).Validate cohortId argument. CohortId can either be a cohort_definition_id
value, a cohort_name or a tidyselect expression referring to cohort_names. If
you want to support tidyselect expressions please use the function as:
validateCohortIdArgument({{cohortId}}, cohort).
validateCohortIdArgument( cohortId, cohort, null = TRUE, empty = TRUE, validation = "error", nm = deparse1(substitute(cohortId), backtick = TRUE), call = parent.frame() )validateCohortIdArgument( cohortId, cohort, null = TRUE, empty = TRUE, validation = "error", nm = deparse1(substitute(cohortId), backtick = TRUE), call = parent.frame() )
cohortId |
A cohortId vector to be validated. |
cohort |
A |
null |
Whether |
empty |
Whether it can be empty. |
validation |
How to perform validation: "error", "warning". |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cohortTables = list( cohort = dplyr::tibble( cohort_definition_id = 1L, subject_id = 1L, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2021-02-10") ) ), cdmName = "mock" ) validateCohortIdArgument(NULL, cdm$cohort) validateCohortIdArgument(1L, cdm$cohort) validateCohortIdArgument(2L, cdm$cohort, validation = "warning")cdm <- cdmFromTables( tables = list( "person" = dplyr::tibble( person_id = c(1, 2, 3), gender_concept_id = 0, year_of_birth = 1990, race_concept_id = 0, ethnicity_concept_id = 0 ), "observation_period" = dplyr::tibble( observation_period_id = 1:3, person_id = 1:3, observation_period_start_date = as.Date("2000-01-01"), observation_period_end_date = as.Date("2023-12-31"), period_type_concept_id = 0 ) ), cohortTables = list( cohort = dplyr::tibble( cohort_definition_id = 1L, subject_id = 1L, cohort_start_date = as.Date("2020-01-01"), cohort_end_date = as.Date("2021-02-10") ) ), cdmName = "mock" ) validateCohortIdArgument(NULL, cdm$cohort) validateCohortIdArgument(1L, cdm$cohort) validateCohortIdArgument(2L, cdm$cohort, validation = "warning")
Validate whether a variable points to a certain existing column in a table.
validateColumn( column, x, type = c("character", "date", "logical", "numeric", "integer"), validation = "error", null = FALSE, empty = TRUE, nm = deparse1(substitute(column), backtick = TRUE), call = parent.frame() )validateColumn( column, x, type = c("character", "date", "logical", "numeric", "integer"), validation = "error", null = FALSE, empty = TRUE, nm = deparse1(substitute(column), backtick = TRUE), call = parent.frame() )
column |
Name of a column that you want to check exists in |
x |
Table to check if the column exists. |
type |
Type of the column. |
validation |
How to perform validation: "error", "warning". |
null |
Whether |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
the validated name
x <- dplyr::tibble(a = 1, b = "xxx") validateColumn("a", x, validation = "warning") validateColumn("a", x, type = "character", validation = "warning") validateColumn("a", x, type = "numeric", validation = "warning") validateColumn("not_existing", x, type = "numeric", validation = "warning")x <- dplyr::tibble(a = 1, b = "xxx") validateColumn("a", x, validation = "warning") validateColumn("a", x, type = "character", validation = "warning") validateColumn("a", x, type = "numeric", validation = "warning") validateColumn("not_existing", x, type = "numeric", validation = "warning")
Validate conceptSet argument. It can either be a list, a codelist, a concept set expression or a codelist with details. The output will always be a codelist.
validateConceptSetArgument( conceptSet, cdm = NULL, empty = TRUE, validation = "error", nm = deparse1(substitute(conceptSet), backtick = TRUE), call = parent.frame() )validateConceptSetArgument( conceptSet, cdm = NULL, empty = TRUE, validation = "error", nm = deparse1(substitute(conceptSet), backtick = TRUE), call = parent.frame() )
conceptSet |
It can be either a named list of concepts or a codelist, codelist_with_details or concept_set_expression object. |
cdm |
A |
empty |
Whether it can be empty. |
validation |
How to perform validation: "error", "warning". |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
A codelist object.
conceptSet <- list(disease_x = c(1L, 2L)) validateConceptSetArgument(conceptSet)conceptSet <- list(disease_x = c(1L, 2L)) validateConceptSetArgument(conceptSet)
name is not already used in that cdm.Validate name argument. It must be a snake_case character vector. You can add
a cdm object to check that name is not already used in that cdm.
validateNameArgument( name, cdm = NULL, validation = "error", null = FALSE, empty = TRUE, nm = deparse1(substitute(name), backtick = TRUE), call = parent.frame() )validateNameArgument( name, cdm = NULL, validation = "error", null = FALSE, empty = TRUE, nm = deparse1(substitute(name), backtick = TRUE), call = parent.frame() )
name |
Name of a new table to be added to a cdm object. |
cdm |
A |
validation |
How to perform validation: "error", "warning". |
null |
If TRUE, name can be NULL |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
# this is a validate name name <- "my_new_table" validateNameArgument(name) # this is not name <- "myTableNAME" validateNameArgument(name, validation = "warning")# this is a validate name name <- "my_new_table" validateNameArgument(name) # this is not name <- "myTableNAME" validateNameArgument(name, validation = "warning")
Validate if two columns are valid Name-Level pair.
validateNameLevel( x, prefix, validation = "error", empty = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame() )validateNameLevel( x, prefix, validation = "error", empty = TRUE, nm = deparse1(substitute(x), backtick = TRUE), call = parent.frame() )
x |
A tibble. |
prefix |
Prefix for the name-level pair, e.g. 'strata' for strata_name-strata_level pair. |
validation |
Either 'error', 'warning' or 'message'. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Will be used by cli to report errors. |
nameStyle argument. If any of the element in ... has length
greater than 1 it must be contained in nameStyle. Note that snake case
notation is used.Validate nameStyle argument. If any of the element in ... has length
greater than 1 it must be contained in nameStyle. Note that snake case
notation is used.
validateNameStyle( nameStyle, ..., empty = TRUE, nm = deparse1(substitute(nameStyle), backtick = TRUE), call = parent.frame() )validateNameStyle( nameStyle, ..., empty = TRUE, nm = deparse1(substitute(nameStyle), backtick = TRUE), call = parent.frame() )
nameStyle |
A character vector. It must contain all the |
... |
Elements to be included. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
invisible nameStyle.
validateNameStyle( nameStyle = "hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("only 1 value") ) ## Not run: validateNameStyle( nameStyle = "hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("value1", "value2") ) ## End(Not run) validateNameStyle( nameStyle = "{other_variable}_hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("value1", "value2") )validateNameStyle( nameStyle = "hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("only 1 value") ) ## Not run: validateNameStyle( nameStyle = "hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("value1", "value2") ) ## End(Not run) validateNameStyle( nameStyle = "{other_variable}_hi_{cohort_name}", cohortName = c("cohort1", "cohort2"), otherVariable = c("value1", "value2") )
Validate a new column of a table
validateNewColumn( table, column, empty = TRUE, validation = "warning", nm = deparse1(substitute(column), backtick = TRUE), call = parent.frame() )validateNewColumn( table, column, empty = TRUE, validation = "warning", nm = deparse1(substitute(column), backtick = TRUE), call = parent.frame() )
table |
The table to check if the column already exists. |
column |
Character vector with the name(s) of the new column(s). |
empty |
Whether it can be empty. |
validation |
How to perform validation: "error", "warning". |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
table without conflicting columns.
x <- dplyr::tibble( column1 = c(1L, 2L), column2 = c("a", "b") ) validateNewColumn(x, "not_exiting_column") validateNewColumn(x, "column1")x <- dplyr::tibble( column1 = c(1L, 2L), column2 = c("a", "b") ) validateNewColumn(x, "not_exiting_column") validateNewColumn(x, "column1")
Validate an omop_table
validateOmopTable( omopTable, version = NULL, cast = FALSE, empty = TRUE, nm = deparse1(substitute(omopTable), backtick = TRUE), call = parent.frame() )validateOmopTable( omopTable, version = NULL, cast = FALSE, empty = TRUE, nm = deparse1(substitute(omopTable), backtick = TRUE), call = parent.frame() )
omopTable |
An omop_table to check. |
version |
Version of the OMOP Common Data Model. |
cast |
Whether to cast columns to the correct type. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
An omop_table object.
Validate whether an object is a valid 'summarised_result' object.
validateResultArgument( result, checkNoDuplicates = FALSE, checkNameLevel = FALSE, checkSuppression = FALSE, empty = TRUE, validation = "error", nm = deparse1(substitute(result), backtick = TRUE), call = parent.frame() )validateResultArgument( result, checkNoDuplicates = FALSE, checkNameLevel = FALSE, checkSuppression = FALSE, empty = TRUE, validation = "error", nm = deparse1(substitute(result), backtick = TRUE), call = parent.frame() )
result |
summarised_result object to validate. |
checkNoDuplicates |
Whether duplicates are not allowed in the result object. |
checkNameLevel |
Whether the name-level paired columns can be correctly split. |
checkSuppression |
Whether the suppression in the result object is well defined. |
empty |
Whether it can be empty. |
validation |
Only error is supported at the moment. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
A summarised_result object.
x <- dplyr::tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() validateResultArgument(x)x <- dplyr::tibble( "result_id" = 1L, "cdm_name" = "eunomia", "group_name" = "cohort_name", "group_level" = "my_cohort", "strata_name" = c("sex", "sex &&& age_group", "sex &&& year"), "strata_level" = c("Female", "Male &&& <40", "Female &&& 2010"), "variable_name" = "number subjects", "variable_level" = NA_character_, "estimate_name" = "count", "estimate_type" = "integer", "estimate_value" = c("100", "44", "14"), "additional_name" = "overall", "additional_level" = "overall" ) |> newSummarisedResult() validateResultArgument(x)
To validate a strata list. It makes sure that elements are unique and point to columns in table.
validateStrataArgument( strata, table, empty = TRUE, nm = deparse1(substitute(strata), backtick = TRUE), call = parent.frame() )validateStrataArgument( strata, table, empty = TRUE, nm = deparse1(substitute(strata), backtick = TRUE), call = parent.frame() )
strata |
A list of characters that point to columns in table. |
table |
A table with columns. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
The same strata input or an error if the input is incorrect.
strata <- list("age", "sex", c("age", "sex")) x <- dplyr::tibble(age = 30L, sex = "Female") validateStrataArgument(strata, x)strata <- list("age", "sex", c("age", "sex")) x <- dplyr::tibble(age = 30L, sex = "Female") validateStrataArgument(strata, x)
Validate a window argument. It must be a list of two elements (window start and window end), both must be numeric, integerish by default, and window start must be lower or equal than window end.
validateWindowArgument( window, snakeCase = TRUE, integerish = TRUE, empty = TRUE, nm = deparse1(substitute(window), backtick = TRUE), call = parent.frame() )validateWindowArgument( window, snakeCase = TRUE, integerish = TRUE, empty = TRUE, nm = deparse1(substitute(window), backtick = TRUE), call = parent.frame() )
window |
time window |
snakeCase |
return default window name in snake case if TRUE |
integerish |
Whether window values must be integerish. |
empty |
Whether it can be empty. |
nm |
Name to use in error messages. Defaults to the expression supplied
to |
call |
Call argument passed to |
time window
validateWindowArgument(list(c(0, 15), c(-Inf, Inf))) validateWindowArgument(list(c(0, 15), c(-Inf, Inf)), snakeCase = FALSE)validateWindowArgument(list(c(0, 15), c(-Inf, Inf))) validateWindowArgument(list(c(0, 15), c(-Inf, Inf)), snakeCase = FALSE)