Skip to content

Commit

Permalink
Decouple scda (#858)
Browse files Browse the repository at this point in the history
closes #834


see also:
- insightsengineering/scda#125
- insightsengineering/scda.2022#123

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 6, 2023
1 parent 603e041 commit fd79164
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 312 deletions.
4 changes: 0 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ Suggests:
MultiAssayExperiment,
R6,
rmarkdown,
scda (>= 0.1.5),
scda.2022 (>= 0.1.3),
shinyvalidate,
testthat (>= 3.1.5),
withr,
Expand All @@ -60,8 +58,6 @@ VignetteBuilder:
RdMacros:
lifecycle
Remotes:
insightsengineering/scda.2022@*release,
insightsengineering/scda@*release,
insightsengineering/teal.code@*release,
insightsengineering/teal.data@*release,
insightsengineering/teal.logger@*release,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# teal 0.13.0.9004

### Miscellaneous

* Removed `scda` package dependency from examples.
# teal 0.13.0

### Breaking changes
Expand Down
71 changes: 43 additions & 28 deletions R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param data (`TealData`)
#' @return dummy filter states
#' @keywords internal
get_dummy_filter <- function(data) { # nolint
example_filter <- function(data) { # nolint
ADSL <- teal.data::get_raw_data(x = data, dataname = "ADSL") # nolint
ADLB <- teal.data::get_raw_data(x = data, dataname = "ADLB") # nolint

Expand Down Expand Up @@ -52,35 +52,50 @@ get_dummy_filter <- function(data) { # nolint
#'
#' @return `cdisc_data`
#' @keywords internal
get_dummy_cdisc_data <- function() { # nolint
teal_with_pkg <- function(pkg, code) {
pkg_name <- paste0("package:", pkg)
if (!pkg_name %in% search()) {
require(pkg, character.only = TRUE)
on.exit(detach(pkg_name, character.only = TRUE))
}
eval.parent(code)
return(invisible(NULL))
}

teal_with_pkg("scda", code = {
ADSL <- scda::synthetic_cdisc_data("latest")$adsl # nolint
ADAE <- scda::synthetic_cdisc_data("latest")$adae # nolint
ADLB <- scda::synthetic_cdisc_data("latest")$adlb # nolint
})
example_cdisc_data <- function() { # nolint
ADSL <- data.frame( # nolint
STUDYID = "study",
USUBJID = 1:10,
SEX = sample(c("F", "M"), 10, replace = TRUE),
AGE = stats::rpois(10, 40)
)
ADTTE <- rbind(ADSL, ADSL, ADSL) # nolint
ADTTE$PARAMCD <- rep(c("OS", "EFS", "PFS"), each = 10) # nolint
ADTTE$AVAL <- c( # nolint
stats::rnorm(10, mean = 700, sd = 200), # dummy OS level
stats::rnorm(10, mean = 400, sd = 100), # dummy EFS level
stats::rnorm(10, mean = 450, sd = 200) # dummy PFS level
)

ADSL$logical_test <- sample(c(TRUE, FALSE, NA), size = nrow(ADSL), replace = TRUE) # nolint
ADSL$SEX[1:150] <- NA # nolint
ADSL$SEX[c(2, 5)] <- NA # nolint

cdisc_data_obj <- teal.data::cdisc_data(
cdisc_dataset(dataname = "ADSL", x = ADSL),
cdisc_dataset(dataname = "ADTTE", x = ADTTE)
)

res <- teal.data::cdisc_data(
teal.data::cdisc_dataset(dataname = "ADSL", x = ADSL),
teal.data::cdisc_dataset(dataname = "ADAE", x = ADAE),
teal.data::cdisc_dataset(dataname = "ADLB", x = ADLB),
code = "
ADSL <- synthetic_cdisc_data(\"latest\")$adsl
ADAE <- synthetic_cdisc_data(\"latest\")$adae
ADLB <- synthetic_cdisc_data(\"latest\")$adlb
"
teal.data::cdisc_dataset(dataname = "ADTTE", x = ADTTE),
code = '
ADSL <- data.frame(
STUDYID = "study",
USUBJID = 1:10,
SEX = sample(c("F", "M"), 10, replace = TRUE),
AGE = rpois(10, 40)
)
ADTTE <- rbind(ADSL, ADSL, ADSL)
ADTTE$PARAMCD <- rep(c("OS", "EFS", "PFS"), each = 10)
ADTTE$AVAL <- c(
rnorm(10, mean = 700, sd = 200),
rnorm(10, mean = 400, sd = 100),
rnorm(10, mean = 450, sd = 200)
)
ADSL$logical_test <- sample(c(TRUE, FALSE, NA), size = nrow(ADSL), replace = TRUE)
ADSL$SEX[c(2, 5)] <- NA
'
)
return(res)
}
Expand All @@ -90,8 +105,8 @@ get_dummy_cdisc_data <- function() { # nolint
#' Returns a new `R6` object on each invocation, not a singleton.
#' @return `FilteredData` with `ADSL` set
#' @keywords internal
get_dummy_datasets <- function() { # nolint
dummy_cdisc_data <- get_dummy_cdisc_data()
example_datasets <- function() { # nolint
dummy_cdisc_data <- example_cdisc_data()
return(teal.slice::init_filtered_data(dummy_cdisc_data))
}

Expand All @@ -102,7 +117,7 @@ get_dummy_datasets <- function() { # nolint
#'
#' @return `teal_modules`
#' @keywords internal
get_dummy_modules <- function() {
example_modules <- function() {
mods <- modules(
label = "d1",
modules(
Expand Down
30 changes: 15 additions & 15 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,41 +111,41 @@
#' @include modules.R
#'
#' @examples
#' library(scda)
#'
#' ADSL <- synthetic_cdisc_data("latest")$adsl
#' new_iris <- transform(iris, id = seq_len(nrow(iris)))
#' new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset("ADSL", ADSL),
#' code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"
#' data = teal_data(
#' dataset("new_iris", new_iris),
#' dataset("new_mtcars", new_mtcars),
#' code = "
#' new_iris <- transform(iris, id = seq_len(nrow(iris)))
#' new_mtcars <- transform(mtcars, id = seq_len(nrow(mtcars)))
#' "
#' ),
#' modules = modules(
#' module(
#' "data source",
#' label = "data source",
#' server = function(input, output, session, data) {},
#' ui = function(id, ...) div(p("information about data source")),
#' filters = "all"
#' ),
#' example_module(),
#' example_module(label = "example teal module"),
#' module(
#' "ADSL AGE histogram",
#' "Iris Sepal.Length histogram",
#' server = function(input, output, session, data) {
#' output$hist <- renderPlot(
#' hist(data[["ADSL"]]()$AGE)
#' hist(data[["new_iris"]]()$Sepal.Length)
#' )
#' },
#' ui = function(id, ...) {
#' ns <- NS(id)
#' plotOutput(ns("hist"))
#' },
#' filters = "ADSL"
#' filters = "new_iris"
#' )
#' ),
#' title = "App title",
#' filter = list(ADSL = structure(list(AGE = list()), filterable = c("AGE", "SEX", "RACE"))),
#' header = tags$h1("Sample App"),
#' footer = tags$p("Copyright 2017 - 2020")
#' title = "App title"
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
Expand Down
4 changes: 2 additions & 2 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#' - `teal_modules`: `tabsetPanel` with each tab corresponding to recursively
#' calling this function on it.
#' @examples
#' mods <- teal:::get_dummy_modules()
#' datasets <- teal:::get_dummy_datasets()
#' mods <- teal:::example_modules()
#' datasets <- teal:::example_datasets()
#' app <- shinyApp(
#' ui = function() {
#' tagList(
Expand Down
4 changes: 2 additions & 2 deletions R/module_tabs_with_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#'
#' @examples
#'
#' mods <- teal:::get_dummy_modules()
#' datasets <- teal:::get_dummy_datasets()
#' mods <- teal:::example_modules()
#' datasets <- teal:::example_datasets()
#'
#' app <- shinyApp(
#' ui = function() {
Expand Down
4 changes: 2 additions & 2 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#' @keywords internal
#'
#' @examples
#' mods <- teal:::get_dummy_modules()
#' raw_data <- reactive(teal:::get_dummy_cdisc_data())
#' mods <- teal:::example_modules()
#' raw_data <- reactive(teal:::example_cdisc_data())
#' app <- shinyApp(
#' ui = function() {
#' teal:::ui_teal("dummy")
Expand Down
14 changes: 1 addition & 13 deletions R/modules_debugging.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,8 @@
#' @keywords internal
#'
#' @examples
#' library(scda)
#' ADSL <- synthetic_cdisc_data("latest")$adsl
#' # by testing with NA values, we will see whether the filtering really works when
#' # we add and remove filters
#' ADSL$SEX[1:150] <- NA
#'
#' app <- init(
#' data = cdisc_data(
#' cdisc_dataset(
#' dataname = "ADSL",
#' x = ADSL
#' ),
#' code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl"
#' ),
#' data = list(iris = iris, mtcars = mtcars),
#' modules = teal:::filter_calls_module(),
#' header = "Simple teal app"
#' )
Expand Down
Loading

0 comments on commit fd79164

Please sign in to comment.