Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/120_append_fs_title@main' into 1…
Browse files Browse the repository at this point in the history
…20_append_fs_title@main
  • Loading branch information
mhallal1 committed Jul 26, 2022
2 parents 9c4c5bb + a72e352 commit 35796f4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: teal.modules.general
Title: General modules to add to a teal application
Version: 0.2.14.9008
Version: 0.2.14.9010
Date: 2022-06-09
Authors@R: c(
person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal.modules.general 0.2.14.9008
# teal.modules.general 0.2.14.9010

### Enhancements
* Added the `teal.reporter` functionality to all modules.
Expand Down
2 changes: 1 addition & 1 deletion R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ui_a_regression <- function(id, ...) {
class = "teal-tooltip",
tagList(
"Outlier definition:",
icon("info-circle"),
icon("circle-info"),
span(
class = "tooltiptext",
paste(
Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ ui_distribution <- function(id, ...) {
class = "teal-tooltip",
tagList(
"Distribution:",
icon("info-circle"),
icon("circle-info"),
span(
class = "tooltiptext",
"Default parameters are optimized with MASS::fitdistr function."
Expand Down
62 changes: 31 additions & 31 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, data
class = "teal-tooltip",
tagList(
"Add **anyna** variable",
icon("info-circle"),
icon("circle-info"),
span(
class = "tooltiptext",
"Describes the number of observations with at least one missing value in any variable."
Expand All @@ -267,7 +267,7 @@ encoding_missing_data <- function(id, summary_per_patient = FALSE, ggtheme, data
class = "teal-tooltip",
tagList(
"Add summary per patients",
icon("info-circle"),
icon("circle-info"),
span(
class = "tooltiptext",
paste(
Expand Down Expand Up @@ -343,32 +343,32 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
teal.code::chunks_push(..., chunks = common_stack)
}

anl_name <- paste0(dataname, "_FILTERED")
anl_filtered <- datasets$get_data(dataname, filtered = TRUE)
assign(anl_name, anl_filtered)
anl_name <- dataname
anl <- datasets$get_data(dataname, filtered = TRUE)
assign(anl_name, anl)
teal.code::chunks_reset(chunks = common_stack)
group_var <- input$group_by_var

if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl_filtered)) {
if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl)) {
common_stack_push(
id = "ANL_FILTERED_selection_call",
id = "ANL_selection_call",
expression = substitute(
expr = ANL_FILTERED <- anl_name[, selected_vars], # nolint
expr = ANL <- anl_name[, selected_vars], # nolint
env = list(anl_name = as.name(anl_name), selected_vars = selected_vars())
)
)
} else {
common_stack_push(
id = "ANL_FILTERED_call",
expression = substitute(expr = ANL_FILTERED <- anl_name, env = list(anl_name = as.name(anl_name))) # nolint
id = "ANL_call",
expression = substitute(expr = ANL <- anl_name, env = list(anl_name = as.name(anl_name))) # nolint
)
}

if (input$summary_type == "By Variable Levels" && !is.null(group_var) && !(group_var %in% selected_vars())) {
common_stack_push(
id = "ANL_FILTERED_group_var_call",
id = "ANL_group_var_call",
substitute(
expr = ANL_FILTERED[[group_var]] <- anl_name[[group_var]], # nolint
expr = ANL[[group_var]] <- anl_name[[group_var]], # nolint
env = list(group_var = group_var, anl_name = as.name(anl_name))
)
)
Expand Down Expand Up @@ -526,7 +526,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
summary_stack_push(
id = "ANL_na_column_call",
expression = substitute(
expr = ANL_FILTERED[[new_col_name]] <- ifelse(rowSums(is.na(ANL_FILTERED)) > 0, NA, FALSE), # nolint
expr = AN[[new_col_name]] <- ifelse(rowSums(is.na(ANL)) > 0, NA, FALSE), # nolint
env = list(new_col_name = new_col_name)
)
)
Expand All @@ -535,7 +535,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
summary_stack_push(
id = "analysis_vars_call",
expression = substitute(
expr = analysis_vars <- setdiff(colnames(ANL_FILTERED), data_keys),
expr = analysis_vars <- setdiff(colnames(ANL), data_keys),
env = list(data_keys = data_keys())
)
)
Expand All @@ -546,13 +546,13 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
expr = summary_plot_obs <- data_frame_call[, analysis_vars] %>%
dplyr::summarise_all(list(function(x) sum(is.na(x)))) %>%
tidyr::pivot_longer(tidyselect::everything(), names_to = "col", values_to = "n_na") %>%
dplyr::mutate(n_not_na = nrow(ANL_FILTERED) - n_na) %>%
dplyr::mutate(n_not_na = nrow(ANL) - n_na) %>%
tidyr::pivot_longer(-col, names_to = "isna", values_to = "n") %>%
dplyr::mutate(isna = isna == "n_na", n_pct = n / nrow(ANL_FILTERED) * 100),
dplyr::mutate(isna = isna == "n_na", n_pct = n / nrow(ANL) * 100),
env = list(data_frame_call = if (!inherits(datasets$get_data(dataname, filtered = TRUE), "tbl_df")) {
quote(tibble::as_tibble(ANL_FILTERED))
quote(tibble::as_tibble(ANL))
} else {
quote(ANL_FILTERED)
quote(ANL)
})
)
)
Expand Down Expand Up @@ -641,13 +641,13 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
)
summary_stack_push(
id = "ndistinct_subjects_call",
expression = quote(ndistinct_subjects <- dplyr::n_distinct(ANL_FILTERED[, parent_keys]))
expression = quote(ndistinct_subjects <- dplyr::n_distinct(ANL[, parent_keys]))
)

summary_stack_push(
id = "summary_plot_patients_call",
expression = quote(
summary_plot_patients <- ANL_FILTERED[, c(parent_keys, analysis_vars)] %>%
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
dplyr::group_by_at(parent_keys) %>%
dplyr::summarise_all(anyNA) %>%
tidyr::pivot_longer(cols = !tidyselect::all_of(parent_keys), names_to = "col", values_to = "anyna") %>%
Expand Down Expand Up @@ -757,7 +757,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
teal.code::chunks_push(
id = "combination_cutoff_call",
expression = quote({
combination_cutoff <- ANL_FILTERED %>%
combination_cutoff <- ANL %>%
dplyr::mutate_all(is.na) %>%
dplyr::group_by_all() %>%
dplyr::tally() %>%
Expand Down Expand Up @@ -951,8 +951,8 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
# Add common code into this stack
teal.code::chunks_push_chunks(common_code_chunks(), chunks = table_stack)

# extract the ANL_FILTERED dataset for use in further validation
anl_filtered <- teal.code::chunks_get_var("ANL_FILTERED", chunks = table_stack)
# extract the ANL dataset for use in further validation
anl <- teal.code::chunks_get_var("ANL", chunks = table_stack)

validate(need(input$count_type, "Please select type of counts"))
if (!is.null(input$group_by_var)) {
Expand All @@ -964,7 +964,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
validate(
need(
is.null(group_var) ||
nrow(unique(anl_filtered[, group_var])) < 100,
nrow(unique(anl[, group_var])) < 100,
"Please select group-by variable with fewer than 100 unique values"
)
)
Expand All @@ -974,10 +974,10 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
vars <- unique(variables_select, group_var)
count_type <- input$count_type # nolint (local variable is assigned and used)

if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl_filtered)) {
if (!is.null(selected_vars()) && length(selected_vars()) != ncol(anl)) {
variables <- selected_vars() # nolint (local variable is assigned and used)
} else {
variables <- colnames(anl_filtered)
variables <- colnames(anl)
}

summ_fn <- if (input$count_type == "counts") {
Expand All @@ -992,7 +992,7 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
id = "summary_data_call_1",
expression = substitute(
expr = {
summary_data <- ANL_FILTERED %>%
summary_data <- ANL %>%
dplyr::mutate(group_var_name := forcats::fct_explicit_na(as.factor(group_var_name), "NA")) %>%
dplyr::group_by_at(group_var) %>%
dplyr::filter(group_var_name %in% group_vals)
Expand All @@ -1014,11 +1014,11 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
table_stack_push(
id = "summary_data_call_1",
expression = substitute(
expr = summary_data <- ANL_FILTERED %>%
expr = summary_data <- ANL %>%
dplyr::summarise_all(summ_fn) %>%
tidyr::pivot_longer(tidyselect::everything(),
names_to = "Variable",
values_to = paste0("Missing (N=", nrow(ANL_FILTERED), ")")
values_to = paste0("Missing (N=", nrow(ANL), ")")
) %>%
dplyr::mutate(`Variable label` = create_cols_labels(Variable), .after = Variable),
env = list(summ_fn = summ_fn)
Expand Down Expand Up @@ -1060,15 +1060,15 @@ srv_missing_data <- function(id, datasets, reporter, dataname, plot_height, plot
by_subject_stack_push(
id = "analysis_vars_call",
expression = substitute(
expr = analysis_vars <- setdiff(colnames(ANL_FILTERED), data_keys),
expr = analysis_vars <- setdiff(colnames(ANL), data_keys),
env = list(data_keys = data_keys())
)
)

by_subject_stack_push(
id = "summary_plot_patients_call",
expression = quote({
summary_plot_patients <- ANL_FILTERED[, c(parent_keys, analysis_vars)] %>%
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
dplyr::group_by_at(parent_keys) %>%
dplyr::mutate(id = dplyr::cur_group_id()) %>%
dplyr::ungroup() %>%
Expand Down
6 changes: 3 additions & 3 deletions R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@ srv_outliers <- function(id, datasets, reporter, outlier_var,
all_categories <- lapply(
unique(anl[[categorical_var]]),
function(x) {
anl_filtered <- anl %>% dplyr::filter(get(categorical_var) == x)
anl <- anl %>% dplyr::filter(get(categorical_var) == x)
anl_outlier2 <- ANL_OUTLIER %>% dplyr::filter(get(categorical_var) == x)
ecdf_df <- anl_filtered %>%
dplyr::mutate(y = stats::ecdf(anl_filtered[[outlier_var]])(anl_filtered[[outlier_var]]))
ecdf_df <- anl %>%
dplyr::mutate(y = stats::ecdf(anl[[outlier_var]])(anl[[outlier_var]]))

dplyr::left_join(
ecdf_df,
Expand Down
2 changes: 1 addition & 1 deletion R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ srv_variable_browser <- function(id, datasets, reporter, datasets_selected, ggpl
class = "teal-tooltip",
tagList(
"Outlier definition:",
icon("info-circle"),
icon("circle-info"),
span(
class = "tooltiptext",
paste(
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ variable_type_icons <- function(var_type) {
checkmate::assert_character(var_type, any.missing = FALSE)

class_to_icon <- list(
numeric = "sort-numeric-up",
integer = "sort-numeric-up",
numeric = "arrow-up-1-9",
integer = "arrow-up-1-9",
logical = "pause",
Date = "calendar",
POSIXct = "calendar",
POSIXlt = "calendar",
factor = "chart-bar",
character = "keyboard",
primary_key = "key",
unknown = "question-circle"
unknown = "circle-question"
)
class_to_icon <- lapply(class_to_icon, function(icon_name) toString(icon(icon_name, lib = "font-awesome")))

Expand Down

0 comments on commit 35796f4

Please sign in to comment.