diff --git a/README.md b/README.md
index ea5a384..0753ca7 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ To provide a one-stop-shop for ADaM test data in the pharmaverse family of packa
# Package Contents
-The ADaM contents of this package is populated by an action that executes the `{admiral}`, `{admiralonco}`, `{admiralophtha}`, `{admiralvaccine}` and `{admiralpeds}` templates and saves the resulting datasets here. This action can be triggered manually by the package maintainers in two scenarios:
+The ADaM datasets in this package are populated by an action that executes the `{admiral}`, `{admiralonco}`, `{admiralophtha}`, `{admiralvaccine}` and `{admiralpeds}` templates and saves the resulting datasets here. This action can be triggered manually by the package maintainers in two scenarios:
- Regularly, upon new releases of these packages;
- Ad-hoc, whenever templates in the above packages have been updated but releases are far away in the calendar. In this case, the ADaM datasets are created using the development version of the templates.
diff --git a/data-raw/create_adams_data.R b/data-raw/create_adams_data.R
index baeb248..106e3ee 100644
--- a/data-raw/create_adams_data.R
+++ b/data-raw/create_adams_data.R
@@ -1,3 +1,35 @@
+# Description: A set of Analysis Data Model (ADaM) datasets constructed using
+# the Study Data Tabulation Model (SDTM) datasets contained in the
+# 'pharmaversesdtm' package and the template scripts from the 'admiral' family
+# of packages. ADaM dataset specifications are described in the CDISC ADaM
+# implementation guide, accessible by creating a free account on
+# .
+#
+# To run, this script collects and saves information from different directories and files:
+# For main code:
+# templates_path:
+# path to ADaM templates where `pkg` is installed (not sourced)
+# (ex: admiral/templates)
+# templates:
+# R files to generate ADaM dataset for `pkg`, prefix `ad_` (templates_path/ad_adae.R)
+# dataset_dir:
+# cache directory where template places ADaM files. (
+# tools::R_user_dir("admiral_templates_data", which = "cache") where generated
+# ADaM.rda files are located.) This cache directory depends upon configuration
+# (see: tools::R_user_dir()) (ex: # "/home/jim/.config/cache/R/admiral_templates_data")
+# -----------------------------------
+# Do we NEED data_path, data_files ??
+# I am ignoring metacore for now.
+# install pharmaversesdtm dep?
+# ----------------------------------
+
+# For function:
+# run_template():
+# tp: template R file to run
+# output_adam_path:
+# pharmaverseadam/data/
+
+
# ensure every packages are installed
library(stringr)
update_pkg <- TRUE
@@ -7,7 +39,7 @@ ignore_templates <- list(
save_rda <- function(data, file_path, new_name) {
if (missing(new_name)) {
- save(data, file = file_path, compress = "bzip2")
+ save(data, file = file_path, comdnepress = "bzip2")
} else {
assign(new_name, data)
save(list = new_name, file = file_path, compress = "bzip2")
@@ -81,20 +113,22 @@ write_labels <- function(data, dataset_name, suffix) {
}
run_template <- function(tp) {
+ # tp is of form `ad_adae.R`
if (!tp %in% ignore_templates_pkg) {
print(sprintf("Running template %s", tp))
- # run template
+ # run template, via Rscript in OS
cmd <- c("Rscript", file.path(templates_path, tp))
system_result <- system2(cmd, stdout = TRUE, stderr = TRUE)
exit_code <- attr(system_result, "status")
tp_basename <- basename(tp)
if (is.null(exit_code)) {
+ # cache directory to store ADaM file rda_file (adae.rda )
dataset_dir <- tools::R_user_dir(sprintf("%s_templates_data", pkg), which = "cache")
rda_file <- gsub(".R", ".rda", tp_basename)
- rda_file <- gsub("ad_", "", rda_file)
+ rda_file <- gsub("ad_", "", rda_file) # now xxxx.rda
+ # load the ADaM file as tibble
data <- load_rda(file.path(dataset_dir, rda_file))
-
print(sprintf("Processing %s file - move it to
pharmaverse and generate the doc", rda_file))
suffix <- ""
@@ -109,7 +143,7 @@ run_template <- function(tp) {
# write labels
data <- write_labels(data, dataset_name, suffix)
- # save it to pharmaverseadam data package
+ # save file to pharmaverseadam data dir (pharmaverseadam/data/\.rda)
save_rda(data, file_path = output_adam_path, new_name = dataset_name)
# write doc
@@ -126,6 +160,8 @@ run_template <- function(tp) {
}
+## main script ----
+
if (update_pkg) {
github_pat <- Sys.getenv("GITHUB_TOKEN") # in case of run through github workflows
# install pharmaversesdtm dep: TODO: see if we install from github or latest release?
@@ -144,7 +180,6 @@ mc <- metacore::spec_to_metacore("inst/extdata/adams-specs.xlsx",
)
packages_list <- c("admiral", "admiralonco", "admiralophtha", "admiralvaccine", "admiralpeds")
-
all_results <- c()
for (pkg in packages_list) {
ignore_templates_pkg <- ignore_templates[pkg]
@@ -160,26 +195,29 @@ for (pkg in packages_list) {
upgrade = "always", force = TRUE
)
}
- # get templates scripts
+ # find templates scripts and run them
+ #
+ # find path to ADaM templates for the installed pkg (ex: ~/R/86_64...library/4.4/admiral/templates)
templates_path <- file.path(system.file(package = pkg), "templates")
+ # templates are R files with a prefix `ad_` (1 or more files)
templates <- list.files(templates_path)
# copy paste pkg/data folder content to pharmaverseadam/data (some templates have dependency with their internal data,
# for example admiral templates have all dependencies with admiral_adsl dataset)
+
+
+ # NEED this? data_path, data_files ?? (remove?)
+
data_path <- file.path(system.file(package = pkg), "data")
data_files <- list.files(data_path)
print(sprintf("Processing templates from %s package", pkg))
# run templates in parallel
- # TODO: reput parallel debug
- # for (tp in templates) {
- # run_template(tp)
- # }
results <- parallel::mclapply(templates, run_template, mc.cores = length(templates))
all_results <- c(all_results, results)
}
-
+# check for errors
for (res in all_results) {
if (!is.null(res$exit_code)) {
print(sprintf("template %s failed - package %s", res$template, res$pkg))