-
Notifications
You must be signed in to change notification settings - Fork 11
Closes #98 - minor word changes in README.md #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2193b1a
992a9c7
0aa4ddb
da5fd1b
931ee9e
27db468
16c6359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,26 @@ | ||||||
| # 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 <https://www.cdisc.org/>. | ||||||
|
|
||||||
| # (Ignoring metacore for now.) | ||||||
|
|
||||||
| # 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) | ||||||
|
|
||||||
| # Do we NEED data_path, data_files ?? | ||||||
| # data_path | ||||||
| # data_files | ||||||
|
|
||||||
| # For function: run_template() | ||||||
| # tp: template R file to run | ||||||
| # dataset_dir: cache dir where template places ADaM file | ||||||
| # (ex: "/home/jim/.config/cache/R/admiral_templates_data") | ||||||
| # output_adam_path: pharmaverseadam/data/ | ||||||
|
|
||||||
|
|
||||||
| # ensure every packages are installed | ||||||
| library(stringr) | ||||||
| update_pkg <- TRUE | ||||||
|
|
@@ -81,20 +104,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) | ||||||
| # 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 +134,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/adae.rda) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will adopt your notation ( pharmaverseadam/data/<adamname>.rda) |
||||||
| save_rda(data, file_path = output_adam_path, new_name = dataset_name) | ||||||
|
|
||||||
| # write doc | ||||||
|
|
@@ -126,6 +151,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 +171,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 +186,29 @@ for (pkg in packages_list) { | |||||
| upgrade = "always", force = TRUE | ||||||
| ) | ||||||
| } | ||||||
| # get templates scripts | ||||||
| # find templates scripts and rum them | ||||||
|
manciniedoardo marked this conversation as resolved.
Outdated
|
||||||
| # | ||||||
| # 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) | ||||||
|
|
||||||
|
|
||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can keep this because it's useful for logging purposes |
||||||
| # 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)) | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.