| Title: | ADaM Program Generation Through Declarative Specifications |
|---|---|
| Description: | Provides tools for generating ADaM programs in clinical trials using a declarative approach. Users specify what data structure and derivations they need through YAML-based specifications, rather than writing imperative code. The package handles dependency tracking between columns and rows, orchestrates code components, and automatically generates executable R programs for ADaM dataset creation. |
| Authors: | Matthew Phelps [aut, cre], Nicolai Skov Johnsen [aut], Aksel Thomsen [aut], Michael Hedegaard Thomsen [aut] |
| Maintainer: | Matthew Phelps <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.0.0.9039 |
| Built: | 2026-10-16 08:08:16 UTC |
| Source: | https://github.com/NovoNordisk-OpenSource/mighty |
This function orchestrates the complete workflow for generating ADaM (Analysis Data Model) programs from ADaM specifications and trial metadata. It processes specifications, validates dependencies, creates action sequences, and renders executable R code for ADaM dataset creation.
generate_adam_code( adam_specifications, path_connector_config, check_cross_domain_adam_dependencies = TRUE, data_context = NULL )generate_adam_code( adam_specifications, path_connector_config, check_cross_domain_adam_dependencies = TRUE, data_context = NULL )
adam_specifications |
Character string. Directory path containing ADaM
specification YAML files (one per domain) and optionally a |
path_connector_config |
Character string. File path to the connector
configuration file (e.g., |
check_cross_domain_adam_dependencies |
Logical. If |
data_context |
Optional list or environment providing additional context
about available data sources for executable program generation. If |
The function executes the following workflow:
Reads and validates ADaM specifications and trial metadata
Sets up initial action configurations with dependency validation
Adds domain initialization, filtering, and data reading actions
Creates dependency graph and organizes actions in execution order
Adds data writing actions and checks executable status
Renders R code for both complete and executable program sets
Compiles individual actions into complete, runnable programs
Each generated program includes all necessary data transformations, derivations, and output operations for creating a specific ADaM dataset according to the provided specifications.
A named list containing the complete ADaM program generation results:
Named list of complete R programs, one per ADaM domain. Each element is a character string containing a fully executable R script. Programs include all dependency-ordered actions and are ready to execute independently. Names are prefixed with the required execution order.
For debugging only. Data.table containing the complete action sequence with fully rendered R code for all programs. Each row represents a single action with action metadata. Actions are ordered by dependency requirements within each domain. This provides a detailed view of the execution plan before compilation into complete programs.
Named list of programs that can be executed with the currently
available data sources (as determined by data_context). Structure identical to programs
but includes only code where all required input data is available. If data_context
is NULL, this will match programs. Used to identify which ADaM derivations can be generated
given the current data availability.
For debugging only. Data.table containing the action sequence for executable
programs only. Structure similar to program_sequence but filtered to include only actions
from code that can be executed with available data. Provides visibility into which
specific transformations will run when executing the available programs.
For debugging only. Data.table defining the dependency graph between actions.
Contains columns parent_node and node_id, representing directed edges where parent
actions must execute before child actions. Edges are created from both column dependencies
(when one action produces a column another action consumes) and row dependencies
(explicit row-level operations). Includes synthetic edges connecting actions with no
dependencies to domain initialization actions. Self-referential edges are removed.
Used for debugging action execution order and dependency resolution.
For debugging only. Data.table containing base action configurations
before code rendering and program organization. Each row represents a single action with
columns: node_id (unique action identifier), domain (ADaM domain name), code_id
(reference to code component or NA), type (action type: col_copy, col_rename, col_mutate,
col_echo, col_compute, row_compute, init_domain, or filter_domain), outputs (list column of
character vectors showing columns produced), depend_cols (nested data.table with
column_name, domain, and domain_type showing column dependencies), depend_rows (list
of node_ids this action depends on for row operations), and parameters (named list of
user-provided parameters). Reflects the internal action data model before execution
ordering. Used for debugging action setup and dependency validation.
For debugging only. Named list of code components that were successfully
rendered using Mustache templates during the generation process. Each element contains
the rendered R code for a specific component (e.g., derivation functions). Component
names correspond to code_id values referenced in the action specifications. Used for
inspecting how template parameters were resolved and for debugging component rendering.
ADaM specification file must be a valid YAML file with ADaM specifications following the schema defined in mighty.metadata
Trial metadata file must contain valid study configuration
Connector configuration file path must be valid for the generated programs to execute
The function will stop execution if:
ADaM specifications or trial metadata files cannot be read or are invalid
Dependency validation fails (missing required columns)
Trial configuration is malformed
## Not run: # Generate ADaM programs with full dependency checking result <- generate_adam_code( adam_specifications = "path/to/yaml_specs_directory", path_connector_config = "path/to/trial_directory/_connector.yml", check_cross_domain_adam_dependencies = TRUE ) # Access generated programs adsl_program <- result$programs$ADSL executable_programs <- result$executable_programs ## End(Not run)## Not run: # Generate ADaM programs with full dependency checking result <- generate_adam_code( adam_specifications = "path/to/yaml_specs_directory", path_connector_config = "path/to/trial_directory/_connector.yml", check_cross_domain_adam_dependencies = TRUE ) # Access generated programs adsl_program <- result$programs$ADSL executable_programs <- result$executable_programs ## End(Not run)
Writes generated ADaM programs to individual R files and optionally applies code styling.
write_adam_programs(programs, dir, style = FALSE)write_adam_programs(programs, dir, style = FALSE)
programs |
Named list. Each element contains program code as character vector, with names used as file names (without .R extension). |
dir |
Character. Output directory path where R files will be written. |
style |
Logical. Whether to apply code styling using |
For each program in the list:
Creates filename by appending ".R" to the list element name
Collapses code vector into single string with newline separators
Writes code to file in specified directory
Optionally applies styler formatting if requested
Logical. Returns TRUE invisibly upon successful completion.
## Not run: # Write programs without styling programs <- list( ADSL = c("library(dplyr)", "ADSL <- DM |> select(USUBJID)"), ADAE = c("library(dplyr)", "ADAE <- AE |> filter(!is.na(AEDECOD))") ) write_adam_programs(programs, dir = "output/adam") # Creates: output/adam/ADSL.R, output/adam/ADAE.R # Write with styling write_adam_programs(programs, dir = "output/adam", style = TRUE) ## End(Not run)## Not run: # Write programs without styling programs <- list( ADSL = c("library(dplyr)", "ADSL <- DM |> select(USUBJID)"), ADAE = c("library(dplyr)", "ADAE <- AE |> filter(!is.na(AEDECOD))") ) write_adam_programs(programs, dir = "output/adam") # Creates: output/adam/ADSL.R, output/adam/ADAE.R # Write with styling write_adam_programs(programs, dir = "output/adam", style = TRUE) ## End(Not run)