insightsengineering / insightsengineering/teal.osprey

SRC does not capture title and footnotes for modules which use `ui_g_decorate`

Open
#46 4 comments 0 reactions 0 assignees View on GitHub
core discussion sme
Dominant language
R
Stars
5
Forks
2
Avg merge
10h 8m
Merged PRs (30d)
3

Description

https://rsconnect.roche.com/content/6127/

For example:

![image](https://user-images.githubusercontent.com/15201933/135866649-73ff03d7-7b61-450b-a9fd-4b38eab06159.png)

Give SRC without title and footnote:

```

#
# Automatically generated R code
#
# Running: /opt/rstudio-connect/mnt/app
# on: rkaub00459.kau.roche.com
# R version: R version 4.0.3 (2020-10-10)
# Date: Mon Oct 4 16:12:01 2021
#
# Current libraries loaded (derived by .libPaths()):
# - /opt/bee/share/nest-packages/UAT_2021_10_01_fin/4.0.3/libs
# - /opt/bee_tools/R/4.0.3/lib64/R/library
#
# Packages versions: teal.osprey (0.1.11), osprey (0.1.11), teal.modules.general
# (0.2.11), ggmosaic (0.3.3), teal.modules.clinical (0.8.10),
# tern (0.7.5), optimx (2020-4.2), rtables (0.3.8.9101),
# magrittr (1.5), teal (0.10.0), ggplot2 (3.3.2), dplyr
# (1.0.2), scda (0.1.1), reticulate (1.18), shiny (1.5.0)
#
# You can run this code interactively on http://r.roche.com
#

# Next two lines are for using NEST packages on BEE (r.roche.com)
source("https://raw.github.roche.com/NEST/nest_on_bee/master/bee_nest_utils.R")
bee_use_nest(release = "UAT_2021_10_01_fin")

library(shiny)
library(reticulate)
library(scda)
library(dplyr)
library(ggplot2)
library(teal)
library(magrittr)
library(rtables)
library(optimx)
library(tern)
library(teal.modules.clinical)
library(ggmosaic)
library(teal.modules.general)
library(osprey)
library(teal.osprey)

ADSL <- synthetic_cdisc_data("latest")$adsl
adsl_labels <- rtables::var_labels(ADSL)
ADSL <- ADSL %>%
mutate(TRTDURD = as.numeric(as.Date(TRTEDTM) - as.Date(TRTSDTM)) + 1, DTHFL = ifelse(!is.na(DTHDT), "Y", NA), EOSSTT = factor(EOSSTT, levels = c("COMPLETED", "ONGOING", "DISCONTINUED"))) %>%
rtables::var_relabel(TRTDURD = "Treatment Duration in Days", DTHFL = "Death Flag", DCSREAS = "Reason for Study Discontinuation", EOSSTT = "End of Study Status") %>%
droplevels()
rtables::var_labels(ADSL)[c(names(adsl_labels))] <- adsl_labels
ADAE <- synthetic_cdisc_data("latest")$adae
ADAE <- ADAE %>%
mutate_at(c("AESOC", "AEBODSYS", "AEHLT", "AEDECOD", "AETERM", "AELLT"), as.character) %>%
mutate(RELFL = ifelse(AEREL == "Y", "Y", "N"), CTC35FL = ifelse(AETOXGR %in% c("3", "4", "5"), "Y", "N"), SERFL = ifelse(AESER == "Y", "Y", "N"), RELSERFL = ifelse(AEREL == "Y" & AESER == "Y", "Y", "N"), AEREL1 = (AEREL == "Y" & ACTARM == "A: Drug X"), AEREL2 = (AEREL == "Y" & ACTARM == "B: Placebo"), ASTDT = as.Date(ASTDTM), AENDT = as.Date(AENDTM)) %>%
rtables::var_relabel(
RELFL = "Related AE",
CTC35FL = "Grade >=3 AE", SERFL = "Serious AE", RELSERFL = "Related Serious AE", AEREL1 = "AE related to A: Drug X", AEREL2 = "AE related to B: Placebo", ASTDT = "Analysis Start Date", AENDT = "Analysis End Date", AESOC = "Primary System Organ Class", AEBODSYS = "Body System or Organ Class", AEHLT = "High Level Term", AEDECOD = "Dictionary-Derived Term", AETERM = "Reported Term for the Adverse Event", AELLT = "Lowest Level Term"
)

## NOTE: Reproducibility of data import and preprocessing was not
## explicitly checked (argument "check = FALSE" is set).
## The app developer has the choice to check the reproducibility
## and might have omitted this step for some reason. Please reach
## out to the app developer for details.

# ADSL MD5 hash at the time of analysis: 5682036b72676588166a34045edb7cfe
# ADAE MD5 hash at the time of analysis: 1c289c802f0c346ed30725f1cf116ff1

ADSL_FILTERED <- ADSL
ADAE_FILTERED_ALONE <- ADAE
ADAE_FILTERED <- dplyr::inner_join(x = ADAE_FILTERED_ALONE, y = ADSL_FILTERED[, c("STUDYID", "USUBJID"), drop = FALSE], by = c("STUDYID", "USUBJID"))

ANL <- merge(x = ADSL_FILTERED[, c("USUBJID", "STUDYID", "ARM"), drop = FALSE], y = ADAE_FILTERED[, c("USUBJID", "STUDYID", "AEDECOD"), drop = FALSE], all.x = FALSE, all.y = FALSE, by = c("USUBJID", "STUDYID"))
term <- ANL[["AEDECOD"]]
id <- ANL$USUBJID
arm <- ANL[["ARM"]]
arm_N <- table(ADSL_FILTERED[["ARM"]])
ref <- "A: Drug X"
trt <- "B: Placebo"
osprey::g_events_term_id(term = term, id = id, arm = arm, arm_N = arm_N, ref = "A: Drug X", trt = "B: Placebo", sort_by = NULL, rate_range = c(0.1, 1), diff_range = c(-0.5, 0.5), reversed = FALSE, conf_level = 0.95, diff_ci_method = "wald", axis_side = "left", fontsize = 5L, draw = TRUE)
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the SRC generation shown in the linked example for a module using ui_g_decorate, then trace the source-capture entry point that produces the displayed R code. Confirm that the module title and footnotes are preserved in the generated SRC and add or update coverage for this case if the project has relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.