Type: Package
Title: Generate Analysis Results Programmes Using ARS Metadata
Version: 0.5.5
Maintainer: Malan Bosman <malanbos@gmail.com>
Description: Analysis Results Standard (ARS), a foundational standard by CDISC (Clinical Data Interchange Standards Consortium), provides a logical data model for metadata describing all components to calculate Analysis Results. https://www.cdisc.org/standards/foundational/analysis-results-standard Using 'siera' package, ARS metadata is ingested (JSON or Excel format), producing programmes to generate Analysis Results Datasets (ARDs).
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (≥ 4.1)
Imports: magrittr, dplyr, tibble, tidyr, jsonlite, stringr, readxl, cli
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0), withr, readr, cards, cardx, covr, parameters, broom, broom.helpers
VignetteBuilder: knitr
URL: https://clymbclinical.github.io/siera/, https://github.com/clymbclinical/siera
BugReports: https://github.com/clymbclinical/siera/issues
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-12-01 15:53:42 UTC; mbosm
Author: Malan Bosman [aut, cre], Clymb Clinical [cph, fnd]
Repository: CRAN
Date/Publication: 2025-12-01 16:10:02 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling 'rhs(lhs)'.


Generate ADaM loading code

Description

Internal helper that inspects the analyses referenced by an output and builds the code required to read the relevant ADaM datasets. Only datasets referenced in the analyses, analysis sets, or data subsets are included in the returned code block.

Usage

.generate_adam_loading_code(
  Anas,
  Analyses,
  AnalysisSets,
  DataSubsets,
  adam_path
)

Arguments

Anas

Subset of analyses tied to the current output (Lopa rows).

Analyses

Analyses metadata for the reporting event.

AnalysisSets

AnalysisSets metadata for the reporting event.

DataSubsets

DataSubsets metadata for the reporting event.

adam_path

Directory containing the ADaM datasets on disk.

Value

Character string containing the code used to load ADaM datasets.


Format numeric values consistently

Description

Internal helper to apply consistent number formatting across analyses.

Usage

.generate_analysis_method_section(
  analysis_methods,
  analysis_method_code_template,
  analysis_method_code_parameters,
  method_id,
  analysis_id,
  output_id,
  envir = parent.frame()
)

Arguments

analysis_methods

AnalysisMethod dataset for the reporting event

analysis_method_code_template

AnalysisMethodCodeTemplate dataset for the reporting event

analysis_method_code_parameters

AnalysisMethodCodeParameters dataset for the reporting event

method_id

MethodId for the method applied to current Analysis

analysis_id

AnalysisId for current Analysis

output_id

OutputId to which current Analysis belongs

envir

Environment (parent environment as default)

Value

Character vector with formatted numbers.


Generate analysis set code and context

Description

Internal helper that builds the code needed to apply an analysis set to the current analysis. The function inspects the ARS metadata to determine filter conditions and returns the templated code together with the name of the resulting population dataset.

Usage

.generate_analysis_set_code(
  j,
  analysis_sets,
  analyses,
  anas,
  analysis_set_id,
  analysis_id
)

Arguments

j

Index of the current analysis within the output loop.

analysis_sets

AnalysisSets metadata for the reporting event.

analyses

Analyses metadata for the reporting event.

anas

The analyses tied to the current output (Lopa subset).

analysis_set_id

Identifier for the analysis set used by the analysis.

analysis_id

Identifier for the analysis that is being generated.

Value

A list containing the generated code and the name of the dataset that holds the filtered analysis population.


Generate data subset code

Description

Internal helper that assembles the code required to apply a data subset for a given analysis. The function prepares default code, augments it with conditional filters when required, and returns metadata describing the subset that was applied.

Usage

.generate_data_subset_code(
  data_subsets,
  subset_id,
  analysis_id,
  analysis_set_dataset,
  file_ext
)

Arguments

data_subsets

DataSubsets metadata for the reporting event.

subset_id

Identifier of the subset tied to the current analysis.

analysis_id

Identifier of the analysis for which code is generated.

analysis_set_dataset

Dataset name produced by the analysis set step.

file_ext

Extension of the source ARS metadata file (json or xlsx).

Value

A list containing the generated code, subset name, and filter expression.


Build a data subset condition

Description

Internal helper that translates ARS data-subset metadata into a filter expression suitable for inclusion in generated R code. Handles comparator translation, type coercion, and workbook-specific formatting differences.

Usage

.generate_data_subset_condition(variable, comparator, value, file_ext)

Arguments

variable

Variable name used in the subset definition.

comparator

Comparison operator from the metadata.

value

Value(s) associated with the comparator.

file_ext

Extension of the source ARS file, used to normalise parsing.

Value

Character string representing the filter expression to apply.


Generate library loading code

Description

Internal helper that returns the boilerplate code used to load the packages required by generated ARD scripts.

Usage

.generate_library_code()

Value

Character string containing the library load block.


Generate the programme header banner

Description

Internal helper that produces the standardised programme banner inserted at the top of each generated ARD script.

Usage

.generate_program_header(OutputId, Output_Name, date)

Arguments

OutputId

Identifier of the output being generated.

Output_Name

Human-readable name of the output.

date

Timestamp used for the header creation date.

Value

Character string containing the formatted programme header.


Read ARS metadata from JSON

Description

Internal helper that ingests ARS metadata stored as JSON and converts it into the harmonised list of tibbles used elsewhere in the package.

Usage

.read_ars_json_metadata(ARS_path)

Arguments

ARS_path

Path to the JSON ARS metadata file.

Value

A list of metadata tables extracted from the JSON file, or 'NULL' when required sections are missing.


Read ARS metadata from disk

Description

Internal helper that validates the ARS file extension and dispatches to the JSON or XLSX reader before returning the harmonised metadata list.

Usage

.read_ars_metadata(ARS_path)

Arguments

ARS_path

Path to the ARS metadata file (JSON or XLSX).

Value

A list containing harmonised metadata tables, or 'NULL' if the file cannot be parsed.


Read ARS metadata from XLSX

Description

Internal helper that ingests ARS metadata stored in Excel workbooks and converts each worksheet into the harmonised metadata list.

Usage

.read_ars_xlsx_metadata(ARS_path)

Arguments

ARS_path

Path to the Excel workbook containing ARS metadata.

Value

A list of metadata tables extracted from the workbook, or 'NULL' when required sheets are missing.


Get path to example ARD scripts, auto-generated by siera

Description

siera comes bundled with some example ARD-producing scripts in its 'inst/script' directory. This function make them easy to access.

Usage

ARD_script_example(path = NULL)

Arguments

path

Name of R file. If 'NULL', the example files will be listed.

Value

A list of example R files (if path is NULL), or a file itself if path is used.

Examples

ARD_script_example()
ARD_script_example("ARD_Out14-1-1.R")

Get path to ARS example files

Description

siera comes bundled with some example files in its 'inst/extdata' directory. This function make them easy to access.

Usage

ARS_example(path = NULL)

Arguments

path

Name of file. If 'NULL', the example files will be listed.

Value

A list of example files (if path is NULL), or a file itself if path is used.

Examples

ARS_example()
ARS_example("Common_Safety_Displays_cards.xlsx")

Ingest ARS (Analysis Results Standard) metadata, produce ARD (Analysis Results Dataset) code for each output

Description

Ingest ARS (Analysis Results Standard) metadata, and meta-programme R scripts that could be run as-is to produce Analysis Results Datasets when ingesting ADaM datasets

Usage

readARS(
  ARS_path,
  output_path = tempdir(),
  adam_path = tempdir(),
  spec_output = ""
)

Arguments

ARS_path

A file containing ARS metadata for a reporting event

output_path

Path to store .R ARD scripts

adam_path

Path to folder containing ADaM datasets, to be run in ARD program

spec_output

The output ID for a specific output to be run from the metadata

Value

R programmes generating ARDs - one for each output (or analysis from an output) specified in the ARS metadata

Examples

# path to file containing ARS metadata

ARS_path <- ARS_example("Common_Safety_Displays_cards.xlsx")

# output path for R programs
output_dir <- tempdir()

# folder containing ADaM datasets
adam_folder <- tempdir()

# run function, write to temp directory
readARS(ARS_path, output_dir, adam_folder)