Skip to content

Commit

Permalink
Address styler complaints.
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-ebs-ext committed Jul 21, 2024
1 parent 9d21c33 commit 7e3c45f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 98 deletions.
2 changes: 1 addition & 1 deletion R/check_papo_call_manual.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nolint start object_usage_linter
# nolint start object_usage_linter # styler: off

# TODO: Generate from mod_patient_profile_API
# This function has been written manually, but mod_patient_profile_API carries
Expand Down
86 changes: 46 additions & 40 deletions R/create_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,62 @@ create_ae_cm_plot <- function(data, x_limits, palette, sl_info, vline_vars, vlin

p <- ggplot2::ggplot(data, ggplot2::aes(x = .data[["start_day_z"]], y = .data[["decode"]]))
p <- p + ggplot2::theme_bw()
p <- p + ggplot2::geom_rect(ggplot2::aes(
xmin = .data[["start_day_z"]],
xmax = .data[["end_day_z"]],
ymin = .data[["decode"]],
ymax = .data[["decode"]],
color = grading
),
size = 3
p <- p + ggplot2::geom_rect(
ggplot2::aes(
xmin = .data[["start_day_z"]],
xmax = .data[["end_day_z"]],
ymin = .data[["decode"]],
ymax = .data[["decode"]],
color = grading
),
size = 3
)

if ("serious_ae" %in% names(data)) {
sae_labels <- ifelse(data[["serious_ae"]], "SAE", "")
p <- p + ggplot2::geom_text(ggplot2::aes(
x = .data[["start_day_z"]],
y = .data[["decode"]],
label = sae_labels
),
colour = "red", nudge_y = 0.25, nudge_x = 1, size = 3
p <- p + ggplot2::geom_text(
ggplot2::aes(
x = .data[["start_day_z"]],
y = .data[["decode"]],
label = sae_labels
),
colour = "red", nudge_y = 0.25, nudge_x = 1, size = 3
)
}

# hack to allow hover info at the beginning of the range through transparent dots
p <- p + ggplot2::geom_point(ggplot2::aes(
x = .data[["start_day_z"]],
y = .data[["decode"]],
color = grading
),
size = 5, alpha = 0, show.legend = FALSE
p <- p + ggplot2::geom_point(
ggplot2::aes(
x = .data[["start_day_z"]],
y = .data[["decode"]],
color = grading
),
size = 5, alpha = 0, show.legend = FALSE
)
p <- p + ggplot2::scale_colour_manual(name = "Legend", values = palette)
p <- p + ggplot2::scale_fill_manual(name = "Legend", values = palette)

if (any(!is.na(data[["arrow_left"]]))) {
p <- p + ggplot2::geom_text(ggplot2::aes(
x = .data[["arrow_left_z"]] - .5,
y = .data[["decode"]],
label = sprintf("\u2190"),
color = grading
),
size = 10, show.legend = FALSE
p <- p + ggplot2::geom_text(
ggplot2::aes(
x = .data[["arrow_left_z"]] - .5,
y = .data[["decode"]],
label = sprintf("\u2190"),
color = grading
),
size = 10, show.legend = FALSE
)
}

if (any(!is.na(data[["arrow_right"]]))) {
p <- p + ggplot2::geom_text(ggplot2::aes(
x = .data[["arrow_right_z"]] + .7,
y = .data[["decode"]],
label = sprintf("\u2192"),
color = grading
),
size = 10, show.legend = FALSE
p <- p + ggplot2::geom_text(
ggplot2::aes(
x = .data[["arrow_right_z"]] + .7,
y = .data[["decode"]],
label = sprintf("\u2192"),
color = grading
),
size = 10, show.legend = FALSE
)
}

Expand Down Expand Up @@ -158,12 +163,13 @@ create_lb_vs_plot <- function(data, date, val, low_limit, high_limit, param, sum
plot <- plot + ggplot2::geom_line(ggplot2::aes(linetype = .data[[param]]), size = 0.1)
} else {
summary_stats_label <- attr(data[[summary_stats]], "label")
plot <- plot + ggplot2::geom_line(ggplot2::aes(
x = .data[["date_z"]],
y = .data[[summary_stats]],
linetype = summary_stats_label
),
size = 0.1
plot <- plot + ggplot2::geom_line(
ggplot2::aes(
x = .data[["date_z"]],
y = .data[[summary_stats]],
linetype = summary_stats_label
),
size = 0.1
)
}

Expand Down
8 changes: 5 additions & 3 deletions R/dressing_room.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ T_is_of_kind <- function(var, type) {
res <- (is.integer(var) || (is.numeric(var) && all(var[is.finite(var)] %% 1 == 0))) && all(var[is.finite(var)] != 0)
} else if (type[["kind"]] == "YN") {
res <- ((is.character(var) && setequal(unique(var), c("Y", "N"))) ||
is.factor(var) && setequal(levels(var), c("Y", "N")))
is.factor(var) && setequal(levels(var), c("Y", "N")))
} else {
browser()
}
Expand Down Expand Up @@ -405,8 +405,10 @@ explorer_ui <- function() {
shiny::div(
class = "col-sm-3",
panel(
shiny::h4("DaVinci's Module Dressing Room", align = "center",
style = "margin-top:0; margin-bottom:2rem; font-weight:bold"),
shiny::h4("DaVinci's Module Dressing Room",
align = "center",
style = "margin-top:0; margin-bottom:2rem; font-weight:bold"
),
inline_shiny_input(
shiny::selectInput(
inputId = "spec", label = NULL,
Expand Down
1 change: 0 additions & 1 deletion R/mod_patient_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ patient_info_server <- function(id, record, subjid_var, column_count = 3) {
shiny::moduleServer(
id,
function(input, output, session) {

# parts in ui_out
output$ui_out <- shiny::renderUI({
shiny::req(nrow(record()) == 1 && ncol(record()) > 0)
Expand Down
14 changes: 7 additions & 7 deletions R/prep_safety_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prep_safety_data <- function(n = 200) {
}

adsl_info <- safetyData::adam_adsl[1:n, ]
adsl_info[["TRTSDT"]] <- robust_ymd(adsl_info[["TRTSDT"]]) |> structure(label = "Treatment Start Date")
adsl_info[["TRTSDT"]] <- robust_ymd(adsl_info[["TRTSDT"]]) |> structure(label = "Treatment Start Date")
adsl_info[["TRTEDT"]] <- robust_ymd(adsl_info[["TRTEDT"]], round_up = TRUE) |> structure(label = "Treatment End Date")
adsl_info[["RFICDT"]] <- robust_ymd(adsl_info[["RFSTDTC"]]) |> structure(label = "Informed Consent Date")
adsl_info[["TRTDUR"]] <- as.numeric(adsl_info[["TRTDUR"]]) |> structure(label = "Treatment duration (days)")
Expand All @@ -44,18 +44,18 @@ prep_safety_data <- function(n = 200) {
# vs
vs_info <- safetyData::adam_advs |>
dplyr::left_join(safetyData::adam_advs |>
dplyr::group_by(.data[["USUBJID"]], .data[["PARAM"]], .data[["VISIT"]]) |>
dplyr::summarise(AVAL_MEAN = mean(as.numeric(.data$AVAL)), .groups = "drop") |>
dplyr::ungroup(), by = c("USUBJID", "PARAM", "VISIT"))
dplyr::group_by(.data[["USUBJID"]], .data[["PARAM"]], .data[["VISIT"]]) |>
dplyr::summarise(AVAL_MEAN = mean(as.numeric(.data$AVAL)), .groups = "drop") |>
dplyr::ungroup(), by = c("USUBJID", "PARAM", "VISIT"))
attr(vs_info[["AVAL_MEAN"]], "label") <- "Mean Value"


# lb
lb_info <- safetyData::adam_adlbc |>
dplyr::left_join(safetyData::adam_adlbc |>
dplyr::group_by(.data[["USUBJID"]], .data[["PARAM"]], .data[["VISIT"]]) |>
dplyr::summarise(AVAL_MEAN = mean(as.numeric(.data$AVAL)), .groups = "drop") |>
dplyr::ungroup(), by = c("USUBJID", "PARAM", "VISIT")) |>
dplyr::group_by(.data[["USUBJID"]], .data[["PARAM"]], .data[["VISIT"]]) |>
dplyr::summarise(AVAL_MEAN = mean(as.numeric(.data$AVAL)), .groups = "drop") |>
dplyr::ungroup(), by = c("USUBJID", "PARAM", "VISIT")) |>
dplyr::filter(
.data$USUBJID %in% adsl_info$USUBJID
)
Expand Down
88 changes: 44 additions & 44 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ output:
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%",
out.width = "100%",
tidy = "styler"
)
```
Expand Down Expand Up @@ -42,50 +42,50 @@ To use `dv.papo` inside a DaVinci app, add the module to your module list. The c
See `vignette("a00-papo")` for further information on how to use `dv.papo` with `dv.manager`.

```{r example, eval = FALSE}
dataset_list <- list(
"demo" = dv.papo:::prep_safety_data(5),
"demo2" = dv.papo:::prep_safety_data(10)
)
dataset_list <- list(
"demo" = dv.papo:::prep_safety_data(5),
"demo2" = dv.papo:::prep_safety_data(10)
)
module_list <- list(
"Patient Profile" = dv.papo::mod_patient_profile(
module_id = "papo",
subject_level_dataset_name = "adsl",
subjid_var = "USUBJID",
summary = list(
vars = c("SUBJID", "SITEID", "ARM", "TRTSDT", "TRTEDT", "AGE", "RACE", "SEX", "BMIBL"),
column_count = 3L
),
listings = list(
"Concomitant Medication" = list(
dataset = "cm"
),
"Adverse Events" = list(
dataset = "adae",
default_vars = c("ASTDT", "ASTDY", "AENDT", "AENDY", "AEDECOD", "AESEV")
)
),
plots = list(
timeline_info = c(trt_start_date = "TRTSDT", trt_end_date = "TRTEDT"),
range_plots = list(
"Adverse Events" = list(
dataset = "adae",
vars = c(
start_date = "ASTDT", end_date = "AENDT",
decode = "AEDECOD", grading = "AESEV", serious_ae = "AESER"
),
tooltip = c("AE Start Day: " = "ASTDY", "AE End Day: " = "AENDY")
)
),
value_plots = list(),
vline_vars = c("Informed Consent Date" = "RFICDT")
)
module_list <- list(
"Patient Profile" = dv.papo::mod_patient_profile(
module_id = "papo",
subject_level_dataset_name = "adsl",
subjid_var = "USUBJID",
summary = list(
vars = c("SUBJID", "SITEID", "ARM", "TRTSDT", "TRTEDT", "AGE", "RACE", "SEX", "BMIBL"),
column_count = 3L
),
listings = list(
"Concomitant Medication" = list(
dataset = "cm"
),
"Adverse Events" = list(
dataset = "adae",
default_vars = c("ASTDT", "ASTDY", "AENDT", "AENDY", "AEDECOD", "AESEV")
)
),
plots = list(
timeline_info = c(trt_start_date = "TRTSDT", trt_end_date = "TRTEDT"),
range_plots = list(
"Adverse Events" = list(
dataset = "adae",
vars = c(
start_date = "ASTDT", end_date = "AENDT",
decode = "AEDECOD", grading = "AESEV", serious_ae = "AESER"
),
tooltip = c("AE Start Day: " = "ASTDY", "AE End Day: " = "AENDY")
)
),
value_plots = list(),
vline_vars = c("Informed Consent Date" = "RFICDT")
)
)
dv.manager::run_app(
data = dataset_list,
module_list = module_list,
filter_data = "adsl"
)
)
dv.manager::run_app(
data = dataset_list,
module_list = module_list,
filter_data = "adsl"
)
```
1 change: 0 additions & 1 deletion tests/testthat/apps/root/app.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# TODO(miguel): Avoid having to install the package when testing locally by following
# dv.biomarker.general/browse/tests/testthat/app/app.R?at=dev # nolint (false positive for commented_code_linter)
# to run the current version of the code
Expand Down
2 changes: 1 addition & 1 deletion vignettes/a02-communication.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module_list <- list(
module_id = "mod2",
..., # ommitted for brevity
receiver_id = "mod1"
)
)
)
```

Expand Down

0 comments on commit 7e3c45f

Please sign in to comment.