| Title: | Tidy Utilities for Observational Medical Outcomes Partnership Common Data Model Workflows |
|---|---|
| Description: | Lightweight utilities for working with OMOP (Observational Medical Outcomes Partnership) Common Data Model (CDM) data in the Observational Health Data Sciences and Informatics ecosystem. Provides base-R re-implementations of common 'purrr' functional helpers, tools to convert plain data frames into 'CIRCE' concept set expressions, SQL generators for resolving concept sets against an OMOP vocabulary schema without requiring 'CirceR'. |
| Authors: | Alexander Alexeyuk [aut, cre] |
| Maintainer: | Alexander Alexeyuk <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-05-15 09:13:22 UTC |
| Source: | https://github.com/cran/tidyOhdsiSolutions |
Converts a formula, existing function, or atomic vector into a
function suitable for use in the map, map2, and
pmap families.
as_mapper(.f)as_mapper(.f)
.f |
A function, one-sided formula, or atomic vector.
|
This helper mirrors the behaviour of
purrr::as_mapper for the formula and function
cases, providing a dependency-free alternative for internal use.
A function.
When .f is already a function or an atomic vector it is
returned as-is.
When .f is a formula the returned function accepts
... and evaluates the formula's right-hand side with the
positional bindings described above.
f <- as_mapper(~ .x + 1) f(10) g <- as_mapper(~ .x + .y) g(2, 3)f <- as_mapper(~ .x + 1) f(10) g <- as_mapper(~ .x + .y) g(2, 3)
Applies buildConceptSetQuery to every element of a named
list of concept set expressions and returns the results as a named list
of SQL strings.
buildConceptSetQueries(conceptSetList, vocabularyDatabaseSchema = "vocabulary")buildConceptSetQueries(conceptSetList, vocabularyDatabaseSchema = "vocabulary")
conceptSetList |
A named list of concept set expressions,
each in CIRCE format (a list with an |
vocabularyDatabaseSchema |
Character. Schema containing the OMOP
vocabulary tables. Defaults to |
A named list of SQL query strings, one per concept set.
Build SQL to resolve a concept set expression without Java/CirceR
buildConceptSetQuery( conceptSetExpression, vocabularyDatabaseSchema = "@vocabulary_database_schema" )buildConceptSetQuery( conceptSetExpression, vocabularyDatabaseSchema = "@vocabulary_database_schema" )
conceptSetExpression |
An R list with structure matching CIRCE concept set format,
or a JSON character string representing such a list. Must contain an |
vocabularyDatabaseSchema |
Character string. Schema where vocabulary tables live.
Defaults to |
A SQL query string that resolves to a set of concept_ids
Builds a complete cohort definition from a named list of concept set expressions. Each concept set is assigned an auto-incremented ID (starting at 0) and all domains across all concept sets contribute to the primary criteria.
cohortFromConceptSet( conceptSetList, limit = "earliest", requiredObservation = c(0L, 0L), end = "observation_period_end_date", endArgs = list(), addSourceCriteria = FALSE )cohortFromConceptSet( conceptSetList, limit = "earliest", requiredObservation = c(0L, 0L), end = "observation_period_end_date", endArgs = list(), addSourceCriteria = FALSE )
conceptSetList |
A named list of concept set expressions. Each element must
be a list with an |
limit |
Character. Event limit: |
requiredObservation |
Integer vector of length 2: days of continuous observation
required |
end |
Character. End strategy: |
endArgs |
A list of parameters for the chosen end strategy. See
|
addSourceCriteria |
Logical. If |
A nested R list representing a complete CirceR cohort expression.
Can be converted to valid JSON via cohortToJson.
Converts the nested R list produced by createConceptSetCohort
or cohortFromConceptSet to a JSON character string that is
compatible with CirceR::cohortExpressionFromJson() and
CirceR::buildCohortQuery().
cohortToJson(cohort)cohortToJson(cohort)
cohort |
A list produced by |
A single character string of pretty-printed JSON.
createConceptSetCohort, cohortFromConceptSet
Iterates over the ConceptSets element of a CirceR-style cohort
definition list and returns the concept set expressions as a named list.
Names are derived from the concept set names, cleaned to lower camel case.
collectCsFromCohort(cohortDonor)collectCsFromCohort(cohortDonor)
cohortDonor |
A named list with the structure of a CirceR cohort
definition. Must contain a |
A named list where each name is a lower-camel-case concept set name and each value is the corresponding CIRCE concept set expression.
Builds a complete cohort definition as a nested R list that matches the
structure expected by CirceR::cohortExpressionFromJson() and
CirceR::buildCohortQuery(). No Java or Capr dependency required.
createConceptSetCohort( conceptSetExpression, name = "Concept Set Cohort", limit = "first", requiredObservation = c(0L, 0L), end = "observation_period_end_date", endArgs = list(), addSourceCriteria = FALSE, codesetId = 0L )createConceptSetCohort( conceptSetExpression, name = "Concept Set Cohort", limit = "first", requiredObservation = c(0L, 0L), end = "observation_period_end_date", endArgs = list(), addSourceCriteria = FALSE, codesetId = 0L )
conceptSetExpression |
An R list with |
name |
Character. Cohort / concept set name. Default |
limit |
Character. Event limit: |
requiredObservation |
Integer vector of length 2: days of continuous observation
required |
end |
Character. End strategy: |
endArgs |
A list of parameters for the chosen end strategy. See
|
addSourceCriteria |
Logical. If |
codesetId |
Integer. The concept set ID to use internally. Default |
A nested R list representing a complete CirceR cohort expression.
Can be serialized to JSON via jsonlite::toJSON() and passed to
CirceR::buildCohortQuery() or CirceR::cohortExpressionFromJson().
A family of indexed mapping functions modelled after
purrr::imap.
.f receives two arguments: the element value and its name
(if .x is named) or its integer position (if .x is
unnamed).
imap(.x, .f, ...) imap_chr(.x, .f, ...) imap_dbl(.x, .f, ...) imap_dfr(.x, .f, ...)imap(.x, .f, ...) imap_chr(.x, .f, ...) imap_dbl(.x, .f, ...) imap_dfr(.x, .f, ...)
.x |
A list or atomic vector. |
.f |
A function or one-sided formula taking two arguments:
the element value ( |
... |
Additional arguments passed to |
When .x has names, the second argument to .f is the
element name (a character string).
When .x is unnamed, the second argument is the positional
index (an integer).
imapA list the same length as .x.
imap_chrA character vector.
imap_dblA double (numeric) vector.
imap_dfrA data.frame formed by
rbind-ing per-element results.
imap_chr(c(a = 1, b = 2), ~ paste(.y, "=", .x)) imap_dbl(10:12, ~ .x + .y)imap_chr(c(a = 1, b = 2), ~ paste(.y, "=", .x)) imap_dbl(10:12, ~ .x + .y)
A family of lightweight mapping functions modelled after
purrr::map.
map() always returns a list; the typed variants
(map_chr, map_dbl, map_int, map_lgl)
return atomic vectors of the indicated type; and the data-frame
variants (map_dfr, map_dfc) row-bind or column-bind
the results into a single data.frame.
map(.x, .f, ...) map_chr(.x, .f, ...) map_dbl(.x, .f, ...) map_int(.x, .f, ...) map_lgl(.x, .f, ...) map_dfr(.x, .f, ...) map_dfc(.x, .f, ...)map(.x, .f, ...) map_chr(.x, .f, ...) map_dbl(.x, .f, ...) map_int(.x, .f, ...) map_lgl(.x, .f, ...) map_dfr(.x, .f, ...) map_dfc(.x, .f, ...)
.x |
A list or atomic vector. |
.f |
A function, one-sided formula, or atomic vector.
Formulas are converted via |
... |
Additional arguments passed to |
These functions provide a dependency-free subset of the
purrr mapping interface.
map() is a thin wrapper around lapply;
the typed variants use vapply with an appropriate
FUN.VALUE template.
mapA list the same length as .x.
map_chrA character vector the same length as
.x.
map_dblA double (numeric) vector the same length as
.x.
map_intAn integer vector the same length as
.x.
map_lglA logical vector the same length as
.x.
map_dfrA data.frame formed by
rbind-ing the per-element results.
map_dfcA data.frame formed by
cbind-ing the per-element results.
as_mapper, map2,
pmap, imap, walk
map(1:3, ~ .x * 2) map_dbl(1:3, ~ .x^2) map_chr(letters[1:3], toupper)map(1:3, ~ .x * 2) map_dbl(1:3, ~ .x^2) map_chr(letters[1:3], toupper)
A family of mapping functions that iterate over two inputs in
parallel, modelled after purrr::map2.
map2() returns a list; the typed variants return atomic
vectors; and the data-frame variants row-bind or column-bind the
results.
map2(.x, .y, .f, ...) map2_chr(.x, .y, .f, ...) map2_dbl(.x, .y, .f, ...) map2_int(.x, .y, .f, ...) map2_lgl(.x, .y, .f, ...) map2_dfr(.x, .y, .f, ...) map2_dfc(.x, .y, .f, ...)map2(.x, .y, .f, ...) map2_chr(.x, .y, .f, ...) map2_dbl(.x, .y, .f, ...) map2_int(.x, .y, .f, ...) map2_lgl(.x, .y, .f, ...) map2_dfr(.x, .y, .f, ...) map2_dfc(.x, .y, .f, ...)
.x, .y
|
Two vectors or lists of the same length (or length one, which is recycled). |
.f |
A function or one-sided formula taking (at least) two
arguments.
Formulas are converted via |
... |
Additional arguments passed to |
All variants are thin wrappers around mapply with
SIMPLIFY = FALSE.
The typed variants coerce the unlisted result to the target type.
map2A list the same length as .x.
map2_chrA character vector.
map2_dblA double (numeric) vector.
map2_intAn integer vector.
map2_lglA logical vector.
map2_dfrA data.frame formed by
rbind-ing per-pair results.
map2_dfcA data.frame formed by
cbind-ing per-pair results.
map2(1:3, 4:6, ~ .x + .y) map2_dbl(1:3, 4:6, `+`)map2(1:3, 4:6, ~ .x + .y) map2_dbl(1:3, 4:6, `+`)
Stop with a styled error message
msg_abort(..., call. = FALSE, class = NULL)msg_abort(..., call. = FALSE, class = NULL)
... |
Message parts |
call. |
Include call in error? Default FALSE |
class |
Optional condition class(es) |
Does not return; stops execution by throwing an error condition.
Print a blank line
msg_blank()msg_blank()
No return value, called for side effects.
Print a bullet point
msg_bullet(...)msg_bullet(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Print a danger / error message (styled, non-stopping)
msg_danger(...)msg_danger(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Print a debug message (only when option is set)
msg_debug(...)msg_debug(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Print a section header
msg_header(title, char = .sym("line"), width = getOption("width", 80L))msg_header(title, char = .sym("line"), width = getOption("width", 80L))
title |
Header text |
char |
Line character |
width |
Console width |
No return value, called for side effects.
Print an informational message
msg_info(...)msg_info(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Print a two-column key-value table
msg_kv(x, pad = 2L)msg_kv(x, pad = 2L)
x |
Named vector / list |
pad |
Padding between columns |
No return value, called for side effects.
Print a named list of items
msg_list(items, header = NULL)msg_list(items, header = NULL)
items |
Named character vector or list |
header |
Optional header line |
No return value, called for side effects.
Print a process / action message
msg_process(...)msg_process(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Simple inline progress counter
msg_progress(total, prefix = "Progress", suffix = "")msg_progress(total, prefix = "Progress", suffix = "")
total |
Total number of items |
prefix |
Text before counter |
suffix |
Text after counter |
A list with $tick(), $reset(), $done() methods
pb <- msg_progress(10, prefix = "Processing") for (i in 1:10) { Sys.sleep(0.05); pb$tick() } pb$done()pb <- msg_progress(10, prefix = "Processing") for (i in 1:10) { Sys.sleep(0.05); pb$tick() } pb$done()
Print a simple rule / divider
msg_rule(char = .sym("line"), width = getOption("width", 80L))msg_rule(char = .sym("line"), width = getOption("width", 80L))
char |
Line character |
width |
Console width |
No return value, called for side effects.
Animated spinner for long-running tasks
msg_spinner(msg = "Working", frames = c("|", "/", "-", "\\"))msg_spinner(msg = "Working", frames = c("|", "/", "-", "\\"))
msg |
Message to display |
frames |
Spinner frames (character vector) |
A list with $spin(), $done(), $fail() methods
sp <- msg_spinner("Loading data") for (i in 1:20) { Sys.sleep(0.05); sp$spin() } sp$done()sp <- msg_spinner("Loading data") for (i in 1:20) { Sys.sleep(0.05); sp$spin() } sp$done()
Print a success message
msg_success(...)msg_success(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Time a block and report duration
msg_timed(expr, msg = "Elapsed", digits = 2L)msg_timed(expr, msg = "Elapsed", digits = 2L)
expr |
Expression to time |
msg |
Label for the timing message |
digits |
Decimal places for seconds |
The value of expr, returned invisibly.
msg_timed(Sys.sleep(0.1), "Sleep")msg_timed(Sys.sleep(0.1), "Sleep")
Print a todo item
msg_todo(...)msg_todo(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Run expr and catch + style any errors/warnings
msg_try(expr, on_error = "abort")msg_try(expr, on_error = "abort")
expr |
Expression to evaluate |
on_error |
What to do: "abort" (re-stop), "warn", "message", "ignore" |
The value of expr if evaluation succeeds, or NULL
invisibly if an error is caught and on_error is not "abort".
Message only when verbose option is TRUE
msg_verbose(..., verbose = NULL)msg_verbose(..., verbose = NULL)
... |
Passed to |
verbose |
Override; uses |
No return value, called for side effects.
Print a warning message (styled, non-stopping)
msg_warn(...)msg_warn(...)
... |
Message parts (pasted together) |
No return value, called for side effects.
Warn with a styled warning message
msg_warning(..., call. = FALSE, class = NULL)msg_warning(..., call. = FALSE, class = NULL)
... |
Message parts |
call. |
Include call in warning? Default FALSE |
class |
Optional condition class(es) |
No return value, called for side effects.
Safely navigates into a nested list or vector using a sequence of accessors (names, integer positions, or functions), returning a default value when any accessor fails.
pluck(.x, ..., .default = NULL)pluck(.x, ..., .default = NULL)
.x |
A list, vector, or other sub-settable object. |
... |
A sequence of accessors applied left-to-right to
progressively drill into
|
.default |
The value to return if any accessor fails (index out
of bounds, name not found, intermediate or final value is
|
This function provides a dependency-free equivalent of
purrr::pluck.
It is intentionally strict: accessor types other than integer,
character, or function cause an error.
When no accessors are supplied (... is empty), .x
itself is returned.
The value found at the end of the accessor chain, or
.default if any step along the way fails.
x <- list(a = list(b = list(c = 42))) pluck(x, "a", "b", "c") pluck(x, "a", "z", .default = NA) # Positional access pluck(list(10, 20, 30), 2) # Out-of-range returns .default pluck(list(10, 20), 5, .default = -1)x <- list(a = list(b = list(c = 42))) pluck(x, "a", "b", "c") pluck(x, "a", "z", .default = NA) # Positional access pluck(list(10, 20, 30), 2) # Out-of-range returns .default pluck(list(10, 20), 5, .default = -1)
A family of mapping functions that iterate over an arbitrary number
of inputs in parallel, modelled after
purrr::pmap.
pmap() returns a list; the typed variants return atomic
vectors; and the data-frame variants row-bind or column-bind the
results.
pmap(.l, .f, ...) pmap_chr(.l, .f, ...) pmap_dbl(.l, .f, ...) pmap_int(.l, .f, ...) pmap_lgl(.l, .f, ...) pmap_dfr(.l, .f, ...) pmap_dfc(.l, .f, ...)pmap(.l, .f, ...) pmap_chr(.l, .f, ...) pmap_dbl(.l, .f, ...) pmap_int(.l, .f, ...) pmap_lgl(.l, .f, ...) pmap_dfr(.l, .f, ...) pmap_dfc(.l, .f, ...)
.l |
A list of vectors or lists, all of the same length.
Each element of |
.f |
A function or one-sided formula.
The function should accept as many arguments as there are elements
in |
... |
Additional arguments passed to |
All variants delegate to mapply via
do.call, passing the elements of .l as
parallel arguments.
pmapA list whose length equals the common length of
the elements of .l.
pmap_chrA character vector.
pmap_dblA double (numeric) vector.
pmap_intAn integer vector.
pmap_lglA logical vector.
pmap_dfrA data.frame formed by
rbind-ing per-index results.
pmap_dfcA data.frame formed by
cbind-ing per-index results.
pmap(list(1:3, 4:6, 7:9), ~ ..1 + ..2 + ..3) pmap_dbl(list(a = 1:3, b = 4:6), function(a, b) a * b)pmap(list(1:3, 4:6, 7:9), ~ ..1 + ..2 + ..3) pmap_dbl(list(a = 1:3, b = 4:6), function(a, b) a * b)
Convenience wrapper around toConceptSets for a single concept set.
toConceptSet( df, name = "Concept Set", connection = NULL, vocabularyDatabaseSchema = NULL )toConceptSet( df, name = "Concept Set", connection = NULL, vocabularyDatabaseSchema = NULL )
df |
A data.frame/tibble with at minimum a |
name |
Character. Name for the concept set. |
connection |
Optional DatabaseConnector connection. |
vocabularyDatabaseSchema |
Optional vocabulary schema. |
A single concept set expression list with $items.
Takes a named list of tibbles (each with concept details and flags) and converts them to the full R list structure matching the CIRCE concept set format. Optionally resolves concept metadata from a CDM database connection.
toConceptSets(x, connection = NULL, vocabularyDatabaseSchema = NULL)toConceptSets(x, connection = NULL, vocabularyDatabaseSchema = NULL)
x |
A named list of data.frames/tibbles. Each must contain at minimum:
Optional columns (defaults applied if missing):
|
connection |
Optional. A |
vocabularyDatabaseSchema |
Character. Required if |
A named list of concept set expressions, each with an $items element
in CIRCE format.
Execute .f on each element (or pair / tuple of elements) for
its side effects, returning the input invisibly.
walk() iterates over a single input, walk2() over two
inputs in parallel, and pwalk() over an arbitrary number of
inputs stored in a list.
walk(.x, .f, ...) walk2(.x, .y, .f, ...) pwalk(.l, .f, ...)walk(.x, .f, ...) walk2(.x, .y, .f, ...) pwalk(.l, .f, ...)
.x |
A list or atomic vector. |
.f |
A function, one-sided formula, or atomic vector.
Formulas are converted via |
... |
Additional arguments passed to |
.y |
A vector or list the same length as |
.l |
A list of vectors or lists of equal length
(used by |
These functions are the side-effect counterparts of map,
map2, and pmap, respectively.
walkInvisibly returns .x.
walk2Invisibly returns .x.
pwalkInvisibly returns .l.
walk(1:3, print) walk2(letters[1:3], 1:3, function(l, n) cat(l, "=", n, "\n"))walk(1:3, print) walk2(letters[1:3], 1:3, function(l, n) cat(l, "=", n, "\n"))