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 #246

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL,
indentation_linter = NULL
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL
)
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Depends:
goshawk (>= 0.1.15),
R (>= 3.6),
shiny,
teal (>= 0.14.0.9019)
teal (>= 0.14.0.9027)
Imports:
checkmate,
colourpicker,
Expand All @@ -44,18 +44,18 @@ Imports:
shinyjs,
shinyvalidate,
stats,
teal.code (>= 0.4.0),
teal.code (>= 0.4.1.9009),
teal.logger (>= 0.1.1),
teal.reporter (>= 0.2.0),
teal.transform (>= 0.4.0.9007),
teal.transform (>= 0.4.0.9011),
teal.widgets (>= 0.4.0),
tidyr
Suggests:
knitr,
nestcolor (>= 0.1.0),
rmarkdown,
stringr,
teal.data (>= 0.3.0.9010),
teal.data (>= 0.3.0.9018),
tern (>= 0.7.10),
testthat (>= 2.0),
utils
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# teal.goshawk 0.1.15.9002
# teal.goshawk 0.1.15.9003

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

### Enhancements

Expand Down
10 changes: 4 additions & 6 deletions R/tm_g_gh_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ srv_g_boxplot <- function(id,
hline_vars_labels) {
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")

moduleServer(id, function(input, output, session) {
# reused in all modules
Expand Down Expand Up @@ -531,11 +532,8 @@ srv_g_boxplot <- function(id,
card$append_text(comment)
}
card$append_src(
paste(
teal.code::get_code(
teal.code::join(create_plot(), create_table())
),
collapse = "\n"
teal.code::get_code(
teal.code::join(create_plot(), create_table())
)
)
card
Expand Down
13 changes: 7 additions & 6 deletions R/tm_g_gh_correlationplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ srv_g_correlationplot <- function(id,
vline_vars_labels) {
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")

moduleServer(id, function(input, output, session) {
iv_r <- reactive({
Expand All @@ -403,7 +404,7 @@ srv_g_correlationplot <- function(id,
# filter selected biomarkers
anl_param <- reactive({
dataset_var <- dataname
ANL <- data[[dataname]]() # nolint
ANL <- data()[[dataname]] # nolint
validate_has_data(ANL, 1)

if (length(input$hline_vars) > 0) {
Expand Down Expand Up @@ -492,7 +493,7 @@ srv_g_correlationplot <- function(id,
)

# analysis
private_qenv <- teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)) %>%
private_qenv <- data() %>%
teal.code::eval_code(
code = bquote({
ANL <- .(as.name(dataset_var)) %>% # nolint
Expand All @@ -511,7 +512,7 @@ srv_g_correlationplot <- function(id,
req(constraint_var)

# note that filtered is false thus we cannot use anl_param()$ANL
ANL <- data[[dataname]]() # nolint
ANL <- data()[[dataname]] # nolint
validate_has_data(ANL, 1)

validate_has_variable(ANL, param_var)
Expand All @@ -525,7 +526,7 @@ srv_g_correlationplot <- function(id,

# get min max values
if ((constraint_var == "BASE2" && any(grepl("SCR", visit_freq))) ||
(constraint_var == "BASE" && any(grepl("BL", visit_freq)))) {
(constraint_var == "BASE" && any(grepl("BL", visit_freq)))) { # nolint
val <- stats::na.omit(switch(constraint_var,
"BASE" = ANL$BASE[ANL$AVISITCD == "BL"],
"BASE2" = ANL$BASE2[ANL$AVISITCD == "SCR"],
Expand Down Expand Up @@ -841,7 +842,7 @@ srv_g_correlationplot <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(plot_q()), collapse = "\n"))
card$append_src(teal.code::get_code(plot_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
10 changes: 4 additions & 6 deletions R/tm_g_gh_density_distribution_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ srv_g_density_distribution_plot <- function(id, # nolint
plot_width) {
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")

moduleServer(id, function(input, output, session) {
anl_q_output <- constr_anl_q(
Expand Down Expand Up @@ -445,11 +446,8 @@ srv_g_density_distribution_plot <- function(id, # nolint
card$append_text(comment)
}
card$append_src(
paste(
teal.code::get_code(
teal.code::join(create_plot(), create_table())
),
collapse = "\n"
teal.code::get_code(
teal.code::join(create_plot(), create_table())
)
)
card
Expand Down
5 changes: 3 additions & 2 deletions R/tm_g_gh_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ srv_lineplot <- function(id,
plot_width) {
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")

moduleServer(id, function(input, output, session) {
ns <- session$ns
Expand Down Expand Up @@ -795,7 +796,7 @@ srv_lineplot <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(plot_q()), collapse = "\n"))
card$append_src(teal.code::get_code(plot_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
5 changes: 3 additions & 2 deletions R/tm_g_gh_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ srv_g_scatterplot <- function(id,
plot_width) {
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")

moduleServer(id, function(input, output, session) {
# reused in all modules
Expand Down Expand Up @@ -383,7 +384,7 @@ srv_g_scatterplot <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(plot_q()), collapse = "\n"))
card$append_src(teal.code::get_code(plot_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
5 changes: 3 additions & 2 deletions R/tm_g_gh_spaghettiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ srv_g_spaghettiplot <- function(id,
hline_vars_labels) {
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")

moduleServer(id, function(input, output, session) {
# reused in all modules
Expand Down Expand Up @@ -498,7 +499,7 @@ srv_g_spaghettiplot <- function(id,
card$append_text("Comment", "header3")
card$append_text(comment)
}
card$append_src(paste(teal.code::get_code(plot_q()), collapse = "\n"))
card$append_src(teal.code::get_code(plot_q()))
card
}
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
Expand Down
15 changes: 9 additions & 6 deletions R/utils-arbitrary_lines.r
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ ui_arbitrary_lines <- function(id, line_arb, line_arb_label, line_arb_color, tit
#' @keywords internal
srv_arbitrary_lines <- function(id) {
moduleServer(id, function(input, output, session) {

comma_sep_to_values <- function(values, wrapper_fun = trimws) {
vals <- strsplit(values, "\\s{0,},\\s{0,}")[[1]]
suppressWarnings(wrapper_fun(vals))
Expand All @@ -59,8 +58,9 @@ srv_arbitrary_lines <- function(id) {
iv$add_rule("line_arb", shinyvalidate::sv_optional())
iv$add_rule(
"line_arb",
~ if (any(is.na(comma_sep_to_values(., as.numeric))))
~ if (any(is.na(comma_sep_to_values(., as.numeric)))) {
"Arbitrary lines values should be a comma separated list of numbers"
}
)

iv_color <- shinyvalidate::InputValidator$new()
Expand All @@ -69,14 +69,16 @@ srv_arbitrary_lines <- function(id) {
iv_color$add_rule("line_arb_color", shinyvalidate::sv_optional())
iv_color$add_rule(
"line_arb_color",
~ if (!length(comma_sep_to_values(.)) %in% c(1, length(line_arb())))
~ if (!length(comma_sep_to_values(.)) %in% c(1, length(line_arb()))) {
sprintf(
"Line input error: number of colors should be equal to 1, the number of lines (%d) or left blank for 'red'",
length(line_arb())
)
}
)
iv_color$add_rule("line_arb_color", ~ if (!check_color(comma_sep_to_values(.)))
"The line colors entered cannot be converted to colors in R, please check your spelling")
iv_color$add_rule("line_arb_color", ~ if (!check_color(comma_sep_to_values(.))) {
"The line colors entered cannot be converted to colors in R, please check your spelling"
})
iv$add_validator(iv_color)


Expand All @@ -86,11 +88,12 @@ srv_arbitrary_lines <- function(id) {
iv_label$add_rule("line_arb_label", shinyvalidate::sv_optional())
iv_label$add_rule(
"line_arb_label",
~ if (!length(comma_sep_to_values(.)) %in% c(1, length(line_arb())))
~ if (!length(comma_sep_to_values(.)) %in% c(1, length(line_arb()))) {
sprintf(
"Line input error: number of labels should be equal to 1, the number of lines (%d) or left blank",
length(line_arb())
)
}
)
iv$add_validator(iv_label)
iv
Expand Down
20 changes: 11 additions & 9 deletions R/utils-data_constraints.r
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ keep_data_const_opts_updated <- function(session, input, data, id_param_var) {
# param_id: input id that contains values of PARAMCD to filter for
# param_var: currently only "PARAMCD" is supported
constr_anl_q <- function(session, input, data, dataname, param_id, param_var, trt_group, min_rows) {
checkmate::assert_class(data, "reactive")
checkmate::assert_class(shiny::isolate(data()), "teal_data")
dataset_var <- dataname
if (!identical(param_var, "PARAMCD")) {
# why is there a variable param_id which is provided to this function and always equal to "param"?
Expand All @@ -60,7 +62,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
validate(need(param_var_value, "Please select a biomarker"))
checkmate::assert_string(param_var_value)

ANL <- data[[dataname]]() # nolint
ANL <- data()[[dataname]] # nolint
validate_has_data(ANL, min_rows)

validate_has_variable(ANL, param_var)
Expand All @@ -70,7 +72,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
validate_has_variable(ANL, trt_group)

# analysis
private_qenv <- teal.code::new_qenv(tdata2env(data), code = teal::get_code_tdata(data)) %>%
private_qenv <- data() %>%
teal.code::eval_code(
substitute(ANL <- dataname, list(dataname = as.name(dataname))) # nolint
) %>%
Expand All @@ -91,8 +93,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
constraint_var <- input[["constraint_var"]]
validate(need(constraint_var, "select a constraint variable"))


ANL <- data[[dataname]]() # nolint
ANL <- data()[[dataname]] # nolint
validate_has_data(ANL, min_rows)

validate_has_variable(ANL, param_var)
Expand All @@ -106,7 +107,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr

# get min max values
if ((constraint_var == "BASE2" && any(grepl("SCR", visit_freq))) ||
(constraint_var == "BASE" && any(grepl("BL", visit_freq)))) {
(constraint_var == "BASE" && any(grepl("BL", visit_freq)))) { # nolint
val <- stats::na.omit(switch(constraint_var,
"BASE" = ANL$BASE[ANL$AVISITCD == "BL"],
"BASE2" = ANL$BASE2[ANL$AVISITCD == "SCR"],
Expand Down Expand Up @@ -165,21 +166,22 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
# constraint var means that `param_id.constraint_var` is constrained to the filtered range (or NA),
# e.g. `ALT.BASE2` (i.e. `PARAMCD = ALT & range_filter_on(BASE2)`)
create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows) {

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$condition(~ isTRUE(input$constraint_var != "NONE"))
iv$add_rule("constraint_range_min", shinyvalidate::sv_required("A contraint minimum value is required"))
iv$add_rule("constraint_range_max", shinyvalidate::sv_required("A contraint maximum value is required"))
iv$add_rule(
"constraint_range_min",
~ if (!is.na(input$constraint_range_max) && (.) > input$constraint_range_max)
~ if (!is.na(input$constraint_range_max) && (.) > input$constraint_range_max) {
"constraint min needs to be less than max"
}
)
iv$add_rule(
"constraint_range_max",
~ if (!is.na(input$constraint_range_min) && (.) < input$constraint_range_min)
~ if (!is.na(input$constraint_range_min) && (.) < input$constraint_range_min) {
"constraint min needs to be less than max"
}
)
iv
})
Expand Down Expand Up @@ -223,7 +225,7 @@ create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows)
ANL <- ANL %>% dplyr::filter(USUBJID %in% filtered_usubjids) # nolint
})
)
validate_has_data(private_qenv[["ANL"]], min_rows)
validate_has_data(private_qenv[["ANL"]], min_rows)
}
list(ANL = private_qenv[["ANL"]], qenv = private_qenv)
})
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ plots_per_row_validate_rules <- function(required = TRUE) {
#' an optional description, and the option to append the filter state list.
#' Additionally, it display selected constraint options.
#'
#' @inheritParams teal.reporter::card_template
#' @inheritParams teal::report_card_template
#' @param constraint_list (`list`) a list containing constraint variables, including:
#' - constraint_var (`character(1)`) the constraint variable name.
#' - constraint_range_min (`numeric(1)`) the minimum constraint range value.
Expand Down
9 changes: 9 additions & 0 deletions man/report_card_template_goshawk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.