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

tdata to teal_data #855

Merged
merged 50 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9d0af39
tm_a_gee tdata to teal_data
gogonzo Nov 22, 2023
cc82e90
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Nov 22, 2023
2c22c12
tdata to teal_data
kartikeyakirar Nov 22, 2023
938bc6e
Revert "tdata to teal_data"
kartikeyakirar Nov 22, 2023
83536ff
`tdata` to `teal_data` - `tm_t_tte` (#857)
kartikeyakirar Nov 23, 2023
ce191a3
`tdata` to `teal_data` - `tm_t_mult_events` (#870)
kartikeyakirar Nov 23, 2023
903faae
`tdata` to `teal_data` - `tm_t_summary` (#858)
kartikeyakirar Nov 23, 2023
d695294
`tdata` to `teal_data` - `tm_t_pp_basic_info` (#869)
kartikeyakirar Nov 23, 2023
28090a0
`tdata` to `teal_data` - `tm_t_pp_laboratory` (#868)
kartikeyakirar Nov 23, 2023
de8c308
`tdata` to `teal_data` - `tm_t_pp_medical_history` (#867)
kartikeyakirar Nov 23, 2023
7bd22a9
`tdata` to `teal_data` - `tm_t_pp_prior_medication` (#866)
kartikeyakirar Nov 23, 2023
41d4b53
`tdata` to `teal_data` - `tm_t_shift_by_arm_by_worst` (#864)
kartikeyakirar Nov 23, 2023
95063ef
`tdata` to `teal_data` - `tm_a_mmrm` (#856)
chlebowa Nov 23, 2023
b11ab30
`tdata` to `teal_data` - `tm_t_shift_by_arm` (#863)
kartikeyakirar Nov 23, 2023
9317717
`tdata` to `teal_data` - `tm_t_shift_by_grade` (#862)
kartikeyakirar Nov 23, 2023
9721390
`tdata` to `teal_data` - `tm_t_smq` (#860)
kartikeyakirar Nov 23, 2023
6fe1dcd
`tdata` to `teal_data` - `tm_t_summary_by` (#859)
kartikeyakirar Nov 23, 2023
da479d4
`tdata` to `teal_data` - `tm_g_barchart_simple` (#865)
kartikeyakirar Nov 23, 2023
50588b7
`tdata` to `teal_data` - `tm_t_events_summary` (#875)
kartikeyakirar Nov 23, 2023
8699f8c
`tdata` to `teal_data` - `tm_t_events` (#874)
kartikeyakirar Nov 23, 2023
50dd7e9
`tdata` to `teal_data` - `tm_t_logistic` (#871)
kartikeyakirar Nov 23, 2023
18af906
`tdata` to` teal_data` - `tm_t_exposure` (#872)
kartikeyakirar Nov 23, 2023
0c61d3b
`tdata` to `teal_data` - `tm_g_ci` (#873)
vedhav Nov 23, 2023
cf50017
`tdata` to `teal_data` - `tm_t_events_by_grade` (#877)
kartikeyakirar Nov 23, 2023
2215d23
Revert "`tdata` to `teal_data` - `tm_g_ci`" (#878)
vedhav Nov 23, 2023
310cc11
amend NEWS
Nov 23, 2023
7e5c4b8
fixing styling.
kartikeyakirar Nov 23, 2023
b385f6d
`tdata` to `teal_data` - `tm_t_events_patyear` (#876)
kartikeyakirar Nov 23, 2023
39ca2ba
`tdata` to `teal_data` - `tm_t_abnormality_by_worst_grade` (#885)
averissimo Nov 23, 2023
3c9bf61
`tdata` to `teal_data` - `tm_t_abnormality` (#888)
averissimo Nov 23, 2023
ec88b94
`tdata` to `teal_data` - `tm_t_ancova` (#889)
averissimo Nov 23, 2023
8e8acfa
`tdata` to `teal_data` - `tm_g_lineplot` (#883)
vedhav Nov 23, 2023
c69e6d2
`tdata` to `teal_data` - `tm_g_pp_therapy` (#887)
vedhav Nov 23, 2023
81814be
`tdata` to `teal_data` - `tm_g_pp_patient_timeline` (#886)
vedhav Nov 23, 2023
5116847
`tdata` to `teal_data` - `tm_g_pp_adverse_events` (#884)
vedhav Nov 23, 2023
b3b53ec
`tdata` to `teal_data` - `tm_g_forest_rsp` (#879)
vedhav Nov 23, 2023
bded7c7
`tdata` to `teal_data` - `tm_g_forest_rsp` (#880)
vedhav Nov 23, 2023
4e0cc5e
`tdata` to `teal_data` - `tm_g_forest_rsp` (#881)
vedhav Nov 23, 2023
4fbe205
fix missing prefixes (#892)
chlebowa Nov 24, 2023
aab3fb6
`tdata` to `teal_data` - `tm_g_km` (#882)
vedhav Nov 24, 2023
6bd9e72
`tdata` to` teal_data` - `tm_t_coxreg` (#893)
kartikeyakirar Nov 24, 2023
0f45272
`tdata` to `teal_data` - `tm_t_binary_outcome` (#890)
averissimo Nov 24, 2023
4e67139
`tdata` to `teal_data` - `tm_g_pp_vitals` (#894)
vedhav Nov 24, 2023
edff528
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Nov 24, 2023
01e30a4
Merge branch 'main' into refactor
chlebowa Nov 27, 2023
3870bdb
`get_code` to return concatenated code string (#898)
kartikeyakirar Nov 29, 2023
56829af
merge back from main.
kartikeyakirar Dec 6, 2023
a4d308b
vbump teal.code teal.data teal.transform dependency
kartikeyakirar Dec 8, 2023
943c65a
vbump
vedhav Dec 8, 2023
8841483
teal.code .9009 enough
vedhav Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BugReports:
https://github.com/insightsengineering/teal.modules.clinical/issues
Depends:
R (>= 4.0),
teal (>= 0.14.0.9019),
teal (>= 0.14.0.9027),
tern (>= 0.9.2.9017)
Imports:
assertthat,
Expand All @@ -53,11 +53,11 @@ Imports:
shinyWidgets,
stats,
styler,
teal.code (>= 0.4.0),
teal.data (>= 0.3.0.9010),
teal.code(>= 0.4.1.9009),
teal.data (>= 0.3.0.9018),
teal.logger (>= 0.1.1),
teal.reporter (>= 0.2.1),
teal.transform (>= 0.4.0.9007),
teal.transform (>= 0.4.0.9011),
teal.widgets (>= 0.4.0),
tern.gee (>= 0.1.0),
tern.mmrm (>= 0.2.1),
Expand Down
18 changes: 14 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# teal.modules.clinical 0.8.16.9018

### Breaking Changes
+ Adapted all modules to use `teal_data` objects.

### Enhancements
* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`.
* Added parameter `sort_freq_col` to `tm_t_events` to allow the user to select column to use when sorting by decreasing frequency.
* Added parameter `incl_overall_sum` to `tm_t_events` to allow the user to choose whether overall summary rows are included at the top of the table.
* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`.

### Bug fixes
* Fixed bug in `tm_g_lineplot` forcing module to initialize with a table.

# teal.modules.clinical 0.8.16.9010

### Enhancements
* Added more informative error message when grade mapping error occurs in `tm_t_abnormality_by_worst_grade`.
* Fixed label indentation in `tm_t_abnormality_by_worst_grade`.
Expand All @@ -14,13 +28,9 @@
* Updated `tm_t_pp_basic_info`, `tm_g_pp_therapy`, `tm_g_pp_adverse_events`, and `tm_t_pp_laboratory` to use `rlistings` to print data neatly in reports.
* Updated `tm_g_lineplot` to allow user to remove interval from plot.
* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`.
* Added parameter `sort_freq_col` to `tm_t_events` to allow the user to select column to use when sorting by decreasing frequency.
* Added parameter `incl_overall_sum` to `tm_t_events` to allow the user to choose whether overall summary rows are included at the top of the table.
* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`.

### Bug fixes
* Fixed bug in `tm_t_coxreg` preventing table from being displayed when no covariates are selected.
* Fixed bug in `tm_g_lineplot` forcing module to initialize with a table.

### Miscellaneous
* Updated `control_incidence_rate` parameter names in `tm_t_events_patyear` from `time_unit_input` and `time_unit_output` to `input_time_unit` and `num_pt_year`, respectively, after parameter names were changed in `tern`.
Expand Down
17 changes: 8 additions & 9 deletions R/tm_a_gee.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ template_a_gee <- function(output_table,
#' as.factor() %>%
#' as.numeric() %>%
#' as.factor(),
#' AVALBIN = AVAL < 50 #' Just as an example to get a binary endpoint.
#' AVALBIN = AVAL < 50 # Just as an example to get a binary endpoint.
#' ) %>%
#' droplevels()
#' })
Expand Down Expand Up @@ -369,7 +369,8 @@ srv_gee <- function(id,
basic_table_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
## split_covariates ----
Expand Down Expand Up @@ -401,7 +402,7 @@ srv_gee <- function(id,
input,
output,
id_arm_var = extract_input("arm_var", parentname),
data = data[[parentname]],
data = shiny::reactive(data()[[parentname]]),
arm_ref_comp = arm_ref_comp,
module = "tm_a_gee"
)
Expand Down Expand Up @@ -446,19 +447,17 @@ srv_gee <- function(id,
anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
selector_list = selector_list,
merge_function = "dplyr::inner_join",
join_keys = teal.data::join_keys(data)
merge_function = "dplyr::inner_join"
)

adsl_inputs <- teal.transform::merge_expression_module(
datasets = data,
data_extract = list(arm_var = arm_var),
anl_name = "ANL_ADSL",
join_keys = teal.data::join_keys(data)
anl_name = "ANL_ADSL"
)

anl_q <- shiny::reactive({
teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)) %>%
data() %>%
teal.code::eval_code(as.expression(anl_inputs()$expr)) %>%
teal.code::eval_code(as.expression(adsl_inputs()$expr))
})
Expand Down Expand Up @@ -570,7 +569,7 @@ srv_gee <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(table_q()), collapse = "\n"))
card$append_src(teal.code::get_code(table_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
15 changes: 7 additions & 8 deletions R/tm_a_mmrm.R
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ srv_mmrm <- function(id,
ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
# Reactive responsible for sending a disable/enable signal
Expand Down Expand Up @@ -853,7 +854,7 @@ srv_mmrm <- function(id,
input,
output,
id_arm_var = extract_input("arm_var", parentname), # From UI.
data = data[[parentname]],
data = shiny::reactive(data()[[parentname]]),
arm_ref_comp = arm_ref_comp,
module = "tm_mmrm"
)
Expand Down Expand Up @@ -920,21 +921,19 @@ srv_mmrm <- function(id,
anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
selector_list = selector_list_without_cov,
join_keys = teal.data::join_keys(data),
merge_function = "dplyr::inner_join"
)

adsl_merge_inputs <- teal.transform::merge_expression_module(
datasets = data,
data_extract = list(arm_var = arm_var),
join_keys = teal.data::join_keys(data),
anl_name = "ANL_ADSL"
)

anl_q <- shiny::reactive({
qenv <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data))
qenv2 <- teal.code::eval_code(qenv, as.expression(anl_inputs()$expr))
teal.code::eval_code(qenv2, as.expression(adsl_merge_inputs()$expr))
data() %>%
teal.code::eval_code(code = as.expression(anl_inputs()$expr)) %>%
teal.code::eval_code(code = as.expression(adsl_merge_inputs()$expr))
})

# Initially hide the output title because there is no output yet.
Expand Down Expand Up @@ -1457,7 +1456,7 @@ srv_mmrm <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(all_q()), collapse = "\n"))
card$append_src(teal.code::get_code(all_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
87 changes: 46 additions & 41 deletions R/tm_g_barchart_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ srv_g_barchart_simple <- function(id,
ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
rule_dupl <- function(others) {
Expand Down Expand Up @@ -381,19 +382,17 @@ srv_g_barchart_simple <- function(id,

anl_inputs <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = teal.data::join_keys(data),
selector_list = selector_list
)

anl_q <- shiny::reactive({
qenv <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data))
qenv <- teal.code::eval_code(qenv, as.expression(anl_inputs()$expr))
qenv
data() %>%
teal.code::eval_code(as.expression(anl_inputs()$expr))
})

count_q <- shiny::reactive({
qenv <- anl_q()
teal::validate_has_data(qenv[["ANL"]], 2)
anl_q <- anl_q()
teal::validate_has_data(anl_q[["ANL"]], 2)
groupby_vars <- r_groupby_vars()

# count
Expand All @@ -409,51 +408,46 @@ srv_g_barchart_simple <- function(id,
count_str_to_col_exprs <- sapply(groupby_vars[-1], count_str_to_column_expr)
count_exprs <- c(count_exprs, count_exprs2, count_str_to_col_exprs)
}
qenv2 <- teal.code::eval_code(qenv, code = count_exprs)

data_list <- sapply(teal.data::datanames(data()), function(x) shiny::reactive(data()[[x]]),
simplify = FALSE
)

anl_q <- anl_q %>%
teal.code::eval_code(code = count_exprs)

# add label and slice(1) as all patients in the same subgroup have same n_'s
qenv3 <- teal.code::eval_code(
qenv2,
as.expression(
c(
bquote(attr(counts[[.(get_n_name(groupby_vars))]], "label") <- "Count"),
bquote(
counts <- counts %>%
dplyr::group_by_at(.(as.vector(groupby_vars))) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::select(.(as.vector(groupby_vars)), dplyr::starts_with("n_"))
anl_q <- anl_q %>%
teal.code::eval_code(
as.expression(
c(
bquote(attr(counts[[.(get_n_name(groupby_vars))]], "label") <- "Count"),
bquote(
counts <- counts %>%
dplyr::group_by_at(.(as.vector(groupby_vars))) %>%
dplyr::slice(1) %>%
dplyr::ungroup() %>%
dplyr::select(.(as.vector(groupby_vars)), dplyr::starts_with("n_"))
)
)
)
)
)

# dplyr::select loses labels
teal.code::eval_code(
qenv3,
teal.transform::get_anl_relabel_call(
columns_source = anl_inputs()$columns_source,
datasets = data,
anl_name = "counts"
anl_q %>%
teal.code::eval_code(
teal.transform::get_anl_relabel_call(
columns_source = anl_inputs()$columns_source,
datasets = data_list,
anl_name = "counts"
)
)
)
})

all_q <- shiny::reactive({
teal::validate_inputs(iv_r())
groupby_vars <- as.list(r_groupby_vars()) # so $ access works below

ANL <- count_q()[["ANL"]] # nolint

qenv2 <- teal.code::eval_code(count_q(), substitute(
env = list(groupby_vars = paste(groupby_vars, collapse = ", ")),
plot_title <- sprintf(
"Number of patients (total N = %s) for each combination of (%s)",
nrow(ANL),
groupby_vars
)
))

y_lab <- substitute(
column_annotation_label(counts, y_name),
list(y_name = get_n_name(groupby_vars))
Expand Down Expand Up @@ -487,11 +481,22 @@ srv_g_barchart_simple <- function(id,
ggplot2_args = all_ggplot2_args
)

qenv3 <- teal.code::eval_code(qenv2, code = plot_call)
ANL <- count_q()[["ANL"]] # nolint

all_q <- count_q() %>%
teal.code::eval_code(substitute(
env = list(groupby_vars = paste(groupby_vars, collapse = ", ")),
plot_title <- sprintf(
"Number of patients (total N = %s) for each combination of (%s)",
nrow(ANL),
groupby_vars
)
)) %>%
teal.code::eval_code(code = plot_call)

# explicitly calling print on the plot inside the qenv evaluates
# the ggplot call and therefore catches errors
teal.code::eval_code(qenv3, code = quote(print(plot)))
teal.code::eval_code(all_q, code = quote(print(plot)))
})

plot_r <- shiny::reactive(all_q()[["plot"]])
Expand Down Expand Up @@ -558,7 +563,7 @@ srv_g_barchart_simple <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(all_q()), collapse = "\n"))
card$append_src(teal.code::get_code(all_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
21 changes: 10 additions & 11 deletions R/tm_g_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ srv_g_ci <- function(id, # nolint
ggplot2_args) {
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")

shiny::moduleServer(id, function(input, output, session) {
selector_list <- teal.transform::data_extract_multiple_srv(
Expand Down Expand Up @@ -407,12 +408,10 @@ srv_g_ci <- function(id, # nolint
selector_list = selector_list
)

anl_q <- shiny::reactive(
teal.code::eval_code(
object = teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)),
code = as.expression(anl_inputs()$expr)
)
)
anl_q <- shiny::reactive({
data() %>%
teal.code::eval_code(as.expression(anl_inputs()$expr))
})

all_q <- shiny::reactive({
teal::validate_inputs(iv_r())
Expand All @@ -429,10 +428,10 @@ srv_g_ci <- function(id, # nolint
)
)

x_label <- column_annotation_label(data[[attr(x, "dataname")]](), x)
y_label <- column_annotation_label(data[[attr(y, "dataname")]](), y)
x_label <- column_annotation_label(data()[[attr(x, "dataname")]], x)
y_label <- column_annotation_label(data()[[attr(y, "dataname")]], y)
color_label <- if (length(color)) {
column_annotation_label(data[[attr(color, "dataname")]](), color)
column_annotation_label(data()[[attr(color, "dataname")]], color)
} else {
NULL
}
Expand Down Expand Up @@ -501,7 +500,7 @@ srv_g_ci <- function(id, # nolint
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(all_q()), collapse = "\n"))
card$append_src(teal.code::get_code(all_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
Loading