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

rename to qenv #190

Merged
merged 2 commits into from
Sep 22, 2022
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Breaking changes

* Replaced `chunks` with simpler `Quosure` class.
* Replaced `chunks` with simpler `qenv` class.
* Replaced `datasets` argument containing `FilteredData` with the new arguments `data` (list of reactive datasets) and `filter_panel_api` (`FilterPanelAPI`).

### Enhancements
Expand Down
9 changes: 5 additions & 4 deletions R/tm_g_gh_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
tm_g_gh_boxplot <- function(label,
Expand Down Expand Up @@ -370,6 +370,7 @@ 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")

moduleServer(id, function(input, output, session) {

Expand Down Expand Up @@ -449,7 +450,7 @@ srv_g_boxplot <- function(id,
sprintf("You can not choose %s as x-axis variable for treatment variable %s.", xaxis, trt_group)
))

anl_q()$quosure %>% teal.code::eval_code(
anl_q()$qenv %>% teal.code::eval_code(
code = bquote({
p <- goshawk::g_boxplot(
data = ANL,
Expand Down Expand Up @@ -486,7 +487,7 @@ srv_g_boxplot <- function(id,
font_size <- input$font_size
trt_group <- input$trt_group

anl_q()$quosure %>% teal.code::eval_code(
anl_q()$qenv %>% teal.code::eval_code(
code = bquote({
tbl <- goshawk::t_summarytable(
data = ANL,
Expand Down
19 changes: 10 additions & 9 deletions R/tm_g_gh_correlationplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
tm_g_gh_correlationplot <- function(label,
dataname,
Expand Down Expand Up @@ -438,6 +438,7 @@ 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")

moduleServer(id, function(input, output, session) {

Expand Down Expand Up @@ -539,15 +540,15 @@ srv_g_correlationplot <- function(id,
)

# analysis
private_quosure <- teal.code::new_quosure(data) %>%
private_qenv <- teal.code::new_qenv(tdata2env(data), code = get_code(data)) %>%
teal.code::eval_code(
code = bquote({
ANL <- .(as.name(dataset_var)) %>% # nolint
dplyr::filter(.data[[.(param_var)]] %in% union(.(input$xaxis_param), .(input$yaxis_param)))
})
)
validate_has_data(private_quosure[["ANL"]], 1)
return(list(ANL = ANL, quosure = private_quosure))
validate_has_data(private_qenv[["ANL"]], 1)
return(list(ANL = ANL, qenv = private_qenv))
})

# constraints
Expand Down Expand Up @@ -642,7 +643,7 @@ srv_g_correlationplot <- function(id,
trt_group <- input$trt_group
line_vars <- unique(c(input$hline_vars, input$vline_vars))

private_q <- anl_constraint()$quosure %>% teal.code::eval_code(
private_q <- anl_constraint()$qenv %>% teal.code::eval_code(
code = bquote({
ANL_TRANSPOSED1 <- ANL %>% # nolint
dplyr::select(
Expand Down Expand Up @@ -721,12 +722,12 @@ srv_g_correlationplot <- function(id,
code =
bquote(attr(ANL_TRANSPOSED[[.(trt_group)]], "label") <- attr(ANL[[.(trt_group)]], "label")) # nolint
)
return(list(ANL_TRANSPOSED = private_q[["ANL_TRANSPOSED"]], quosure = private_q))
return(list(ANL_TRANSPOSED = private_q[["ANL_TRANSPOSED"]], qenv = private_q))
})

plot_labels <- reactive({
req(anl_constraint())
ANL <- anl_constraint()$quosure[["ANL"]] # nolint
ANL <- anl_constraint()$qenv[["ANL"]] # nolint

xparam <- ANL$PARAM[ANL[[param_var]] == input$xaxis_param][1]
yparam <- ANL$PARAM[ANL[[param_var]] == input$yaxis_param][1]
Expand Down Expand Up @@ -798,7 +799,7 @@ srv_g_correlationplot <- function(id,
trt_group <- input$trt_group

teal.code::eval_code(
object = plot_data_transpose()$quosure,
object = plot_data_transpose()$qenv,
code = bquote({
# re-establish treatment variable label
p <- goshawk::g_correlationplot(
Expand Down
9 changes: 5 additions & 4 deletions R/tm_g_gh_density_distribution_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
tm_g_gh_density_distribution_plot <- function(label, # nolint
dataname,
Expand Down Expand Up @@ -292,6 +292,7 @@ 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")

moduleServer(id, function(input, output, session) {
anl_q <- constr_anl_q(
Expand Down Expand Up @@ -343,7 +344,7 @@ srv_g_density_distribution_plot <- function(id, # nolint
validate(need(input$trt_group, "Please select a treatment variable"))

teal.code::eval_code(
object = anl_q()$quosure,
object = anl_q()$qenv,
code = bquote({
p <- goshawk::g_density_distribution_plot(
data = ANL,
Expand Down Expand Up @@ -379,7 +380,7 @@ srv_g_density_distribution_plot <- function(id, # nolint
validate(need(trt_group, "Please select a treatment variable"))

teal.code::eval_code(
object = anl_q()$quosure,
object = anl_q()$qenv,
code = bquote(
tbl <- goshawk::t_summarytable(
data = ANL,
Expand Down
17 changes: 9 additions & 8 deletions R/tm_g_gh_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
tm_g_gh_lineplot <- function(label,
dataname,
Expand Down Expand Up @@ -354,6 +354,7 @@ 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")

moduleServer(id, function(input, output, session) {
ns <- session$ns
Expand Down Expand Up @@ -706,20 +707,20 @@ srv_lineplot <- function(id,
)
)

private_quosure <- anl_q()$quosure
private_qenv <- anl_q()$qenv

if (!methods::is(xtick, "waiver") && !is.null(xtick)) {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = bquote({
keep_index <- which(.(xtick) %in% ANL[[.(xaxis)]])
xtick <- (.(xtick))[keep_index] # extra parentheses needed for edge case, e.g. 1:5[keep_index]
xlabel <- (.(xlabel))[keep_index]
})
)
} else if (methods::is(xtick, "waiver")) {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = "
xtick <- ggplot2::waiver()
xlabel <- ggplot2::waiver()
Expand All @@ -732,7 +733,7 @@ srv_lineplot <- function(id,
hline_arb_color <- horizontal_line()$line_arb_color

teal.code::eval_code(
object = private_quosure,
object = private_qenv,
code = bquote({
p <- goshawk::g_lineplot(
data = ANL[complete.cases(ANL[, c(.(yaxis), .(xaxis))]), ],
Expand Down
7 changes: 4 additions & 3 deletions R/tm_g_gh_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
tm_g_gh_scatterplot <- function(label,
Expand Down Expand Up @@ -279,6 +279,7 @@ 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")

moduleServer(id, function(input, output, session) {

Expand Down Expand Up @@ -326,7 +327,7 @@ srv_g_scatterplot <- function(id,

# nolint end
teal.code::eval_code(
object = anl_q()$quosure,
object = anl_q()$qenv,
code = bquote({
# re-establish treatment variable label
p <- goshawk::g_scatterplot(
Expand Down
25 changes: 13 additions & 12 deletions R/tm_g_gh_spaghettiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
#' )
#' )
#' )
#' \dontrun{
#' shinyApp(app$ui, app$server)
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
tm_g_gh_spaghettiplot <- function(label,
Expand Down Expand Up @@ -376,6 +376,7 @@ 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")

moduleServer(id, function(input, output, session) {

Expand Down Expand Up @@ -420,36 +421,36 @@ srv_g_spaghettiplot <- function(id,
hline_vars <- input$hline_vars
# nolint end

private_quosure <- anl_q()$quosure
private_qenv <- anl_q()$qenv

# this code is needed to make sure the waiver attribute
# of ggplot2::waiver is correctly passed to goshawk's spaghettiplot
if (!methods::is(xtick, "waiver")) {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = bquote(xtick <- .(xtick))
)
} else {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = quote(xtick <- ggplot2::waiver())
)
}

if (!methods::is(xlabel, "waiver")) {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = bquote(xlabel <- .(xlabel))
)
} else {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = quote(xlabel <- ggplot2::waiver())
)
}

teal.code::eval_code(
object = private_quosure,
object = private_qenv,
code = bquote({
p <- goshawk::g_spaghettiplot(
data = ANL,
Expand Down
16 changes: 8 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
validate_has_variable(ANL, trt_group)

# analysis
private_quosure <- teal.code::new_quosure(data) %>%
private_qenv <- teal.code::new_qenv(tdata2env(data), code = get_code(data)) %>%
teal.code::eval_code(
substitute(ANL <- dataname, list(dataname = as.name(dataname))) # nolint
) %>%
Expand All @@ -207,8 +207,8 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
dplyr::filter(.(as.name(param_var)) == .(param_var_value))
})
)
validate_has_data(private_quosure[["ANL"]], min_rows)
list(ANL = ANL, quosure = private_quosure)
validate_has_data(private_qenv[["ANL"]], min_rows)
list(ANL = ANL, qenv = private_qenv)
})

observe({
Expand Down Expand Up @@ -293,7 +293,7 @@ constr_anl_q <- function(session, input, data, dataname, param_id, param_var, tr
# e.g. `ALT.BASE2` (i.e. `PARAMCD = ALT & range_filter_on(BASE2)`)
create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows) {
reactive({
private_quosure <- anl_param()$quosure
private_qenv <- anl_param()$qenv

# it is assumed that constraint_var is triggering constraint_range which then trigger this clause
constraint_var <- isolate(input[["constraint_var"]])
Expand All @@ -308,8 +308,8 @@ create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows)

# filter constraint
if (constraint_var != "NONE") {
private_quosure <- teal.code::eval_code(
object = private_quosure,
private_qenv <- teal.code::eval_code(
object = private_qenv,
code = bquote({
# the below includes patients who have at least one non-NA BASE value
# ideally, a patient should either have all NA values or none at all
Expand All @@ -334,10 +334,10 @@ 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_quosure[["ANL"]], min_rows)
validate_has_data(private_qenv[["ANL"]], min_rows)
}

return(list(ANL = private_quosure[["ANL"]], quosure = private_quosure))
return(list(ANL = private_qenv[["ANL"]], qenv = private_qenv))
})
}

Expand Down
4 changes: 2 additions & 2 deletions man/tm_g_gh_boxplot.Rd

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

4 changes: 2 additions & 2 deletions man/tm_g_gh_correlationplot.Rd

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

4 changes: 2 additions & 2 deletions man/tm_g_gh_density_distribution_plot.Rd

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

4 changes: 2 additions & 2 deletions man/tm_g_gh_lineplot.Rd

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

Loading