This vignette shows how to convert an Atlas/Circe cohort JSON file
into executable Capr R code using jsonToCapr() and
jsonToCaprFile().
The common workflow is:
You need a cohort JSON exported from Atlas. In this vignette, we
refer to it as cohort.json.
Use jsonToCapr() when you want the generated code as a
character string.
jsonPath <- "cohort.json"
caprCode <- jsonToCapr(jsonPath, mode = "strict")
cat(caprCode)mode = "strict" stops when unsupported features are
encountered. This is the safest mode when you need a faithful
conversion.
Use jsonToCaprFile() to write generated code directly to
disk.
outRPath <- "cohort_from_atlas.R"
jsonToCaprFile(
jsonPath = jsonPath,
outRPath = outRPath,
mode = "strict"
)The generated script includes library(Capr) and can be
sourced directly.
By convention, generated scripts define a cohortDef
object.
source(outRPath)
# cohortDef should now exist in your environment
cohortJson <- toCohortJson(cohortDef)At this point, cohortJson can be:
sql <- CirceR::buildCohortQuery(
expression = CirceR::cohortExpressionFromJson(cohortJson),
options = CirceR::createGenerateOptions(generateStats = FALSE)
)
nchar(sql) > 0If SQL generation succeeds, the converted cohort is structurally valid for CirceR.
mode = "skip" attempts to continue conversion by
omitting unsupported parts and annotating them in output comments.
caprCodeSkip <- jsonToCapr(jsonPath, mode = "skip")
cat(caprCodeSkip)This mode is useful for exploratory migration, but you should manually review and complete skipped sections before production use.
For reporting or regression checks, use
returnSkipped = TRUE.
result <- jsonToCapr(
jsonPath = jsonPath,
mode = "skip",
returnSkipped = TRUE
)
names(result)
# [1] "lines" "skipped" "emptyGroupWarnings"
result$skippedA practical migration pattern is:
jsonToCaprFile() from Atlas JSON.source() generated script.toCohortJson() to JSON.CirceR::cohortExpressionFromJson() +
buildCohortQuery() as a final validation.This creates a reproducible, version-controlled bridge from Atlas-authored cohorts to Capr-authored pipelines.