Skip to content
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

Consider using logrx to collect system environment, packages used, functions used, and other info #4

Open
parmsam-pfizer opened this issue Jan 14, 2025 · 1 comment

Comments

@parmsam-pfizer
Copy link

parmsam-pfizer commented Jan 14, 2025

We added the ability for users of logrx to write an RDS object last year: https://pharmaverse.github.io/logrx/reference/axecute.html This object could be used as an intermediate to help populate the ADRG with some of the content we are currently discussing. Here are the attributes logrx collects upon execution of an R script: https://pharmaverse.github.io/logrx/articles/logrx.html#log-attributes.

Here's a simple example to help get us started:

adsl.R based on admiral documentation:

library(admiral)
library(dplyr, warn.conflicts = FALSE)
library(pharmaversesdtm)
library(lubridate)
library(stringr)

data("dm")
data("ds")
data("ex")
data("ae")
data("lb")

dm <- convert_blanks_to_na(dm)
ds <- convert_blanks_to_na(ds)
ex <- convert_blanks_to_na(ex)
ae <- convert_blanks_to_na(ae)
lb <- convert_blanks_to_na(lb)

adsl <- dm %>%
  select(-DOMAIN)

adsl <- dm %>%
  mutate(TRT01P = ARM, TRT01A = ACTARM)

# impute start and end time of exposure to first and last respectively,
# do not impute date
ex_ext <- ex %>%
  derive_vars_dtm(
    dtc = EXSTDTC,
    new_vars_prefix = "EXST"
  ) %>%
  derive_vars_dtm(
    dtc = EXENDTC,
    new_vars_prefix = "EXEN",
    time_imputation = "last"
  )

adsl <- adsl %>%
  derive_vars_merged(
    dataset_add = ex_ext,
    filter_add = (EXDOSE > 0 |
                    (EXDOSE == 0 &
                       str_detect(EXTRT, "PLACEBO"))) & !is.na(EXSTDTM),
    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
    order = exprs(EXSTDTM, EXSEQ),
    mode = "first",
    by_vars = exprs(STUDYID, USUBJID)
  ) %>%
  derive_vars_merged(
    dataset_add = ex_ext,
    filter_add = (EXDOSE > 0 |
                    (EXDOSE == 0 &
                       str_detect(EXTRT, "PLACEBO"))) & !is.na(EXENDTM),
    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
    order = exprs(EXENDTM, EXSEQ),
    mode = "last",
    by_vars = exprs(STUDYID, USUBJID)
  )

runner.R script that executes adsl.R via logrx

library(logrx)
library(dplyr)
library(purrr)

axecute("adsl.R", include_rds = T, show_repo_url = T)

log_lst <- readRDS("adsl.Rds")

log_lst$used_packages_functions <- 
  log_lst$used_packages_functions %>% 
  filter(str_detect(library, "package:")) %>%
  # grab package names
  mutate(package = str_match(library, ".*:(.*)")[,2]) %>%
  # filter out for base R packages
  filter(!package %in% c("base", "utils", "tools")) %>%
  # get description for packages used
  mutate(description = map_chr(package, \(x) packageDescription(x)[["Description"]])) %>%
  left_join(
    log_lst$session_info$packages %>% as_tibble() %>% select(package, version = loadedversion), 
    by = "package"
  )

log_lst$used_packages_functions
log_lst$session_info

@nicholas-masel might like this example.

@nicholas-masel
Copy link
Collaborator

@parmsam-pfizer We just need to keep in mind that there are some instances where it cannot identify the correct package for a function. It will show something like [NOT FOUND]. Another place it fails to find the correct package is if the package exports a list of functions, not individual functions. This was discussed a bit here, pharmaverse/logrx#140 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants