CohortDef R6 Class
CohortDef R6 Class
Details
An R6 class that stores key information about cohorts managed by the CohortManifest.
Each CohortDef is a pointer to a file on disk (JSON or SQL) with associated metadata.
The CohortDef class manages cohort metadata and SQL generation.
Upon initialization, it loads and validates cohort definitions from either
JSON (CIRCE format) or SQL files, and creates a hash to uniquely identify
the generated SQL.
Active bindings
label
character to set the label to. If missing, returns the current label.
tags
list of the values to set the tags to. If missing, returns the current tags.
category
character to set the category to. If missing, returns the current category.
Methods
Method new()
Initialize a new CohortDef
Usage
CohortDef$new(label, category, sourceType, tags = list(), filePath)
Arguments
label
Character. The common name of the cohort.
category
Character. Required classification (e.g., 'target', 'exposure', 'outcome').
sourceType
Character. Provenance: 'atlas', 'capr', 'circe', 'sql', or 'derived'.
tags
List. A named list of tags that give metadata about the cohort.
filePath
Character. Path to the cohort file in inputs/cohorts folder (can be .json or .sql).
Get the file path
Method getFilePath()
Returns
Character. Absolute path to the cohort file — safe to read
regardless of the current working directory.
Get the file path for display
Method getDisplayPath()
Usage
CohortDef$getDisplayPath(root = NULL)
Arguments
root
Character or NULL. Study repository root. When supplied, the
path is returned relative to it (the form stored in the manifest);
otherwise the absolute path is returned.
Returns
Character. A human-facing path.
Get the generated SQL
Method getSql()
Returns
Character. The SQL definition of the cohort.
Get the file hash
Method getFileHash()
Returns
Character. MD5 hash of the raw file content on disk.
Get the SQL hash
Method getSqlHash()
Returns
Character. MD5 hash of the normalized SQL definition (line endings standardized).
Get the cohort ID
Method getId()
Returns
Integer. The cohort ID, or NA_integer_ if not set.
Set the cohort ID (internal use)
Method setId()
Arguments
id
Integer. The cohort ID to set.
Format tags as string
Usage
CohortDef$formatTagsAsString()
Returns
Character. Tags formatted as "name: value | name: value".
Get the cohort type
Method getCohortType()
Usage
CohortDef$getCohortType()
Returns
Character. One of 'circe', 'custom', 'custom_derived', 'subset', 'union', 'complement', 'composite', 'oprior', 'tprior', 'censor'.
Set the cohort type (internal use)
Method setCohortType()
Usage
CohortDef$setCohortType(cohortType)
Arguments
cohortType
Character. One of 'circe', 'custom', 'custom_derived', 'subset', 'union', 'complement', 'composite', 'oprior', 'tprior', 'censor'.
Get the source type
Method getSourceType()
Usage
CohortDef$getSourceType()
Returns
Character. One of 'atlas', 'capr', 'sql', 'derived'.
Get the category
Method getCategory()
Returns
Character. The cohort category (e.g., 'target', 'exposure', 'outcome').
Set the category
Method setCategory()
Usage
CohortDef$setCategory(category)
Arguments
category
Character. The cohort category.
Method clone()
The objects of this class are cloneable with this method.
Usage
CohortDef$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.