From a0ef45f469d7b6ae9fc53aeeddb1831dc1b34dfb Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:40:28 +0200 Subject: [PATCH 1/4] 892_joinkeys_outliers@main Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_outliers.R | 63 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index e15ba7635..4a3040f5e 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -438,16 +438,30 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } }) + # Used to create outlier table and the dropdown with additional columns + dataname_first <- isolate(names(data())[[1]]) + + data_obj <- reactive({ + obj <- data() + if (length(join_keys(obj)) == 0) { + if (!".row_id" %in% names(obj[[dataname_first]])) { + obj[[dataname_first]]$.row_id <- seq_len(nrow(obj[[dataname_first]])) + } + join_keys(obj) <- join_keys(join_key(dataname_first, dataname_first, ".row_id")) + } + obj + }) + anl_merged_input <- teal.transform::merge_expression_srv( selector_list = reactive_select_input, - datasets = data, + datasets = data_obj, merge_function = "dplyr::inner_join" ) anl_merged_q <- reactive({ req(anl_merged_input()) teal.code::eval_code( - data(), + data_obj(), paste0( 'library("dplyr");library("tidyr");', # nolint quotes 'library("tibble");library("ggplot2");' @@ -468,9 +482,6 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, sum(is.na(ANL[[outlier_var]])) }) - # Used to create outlier table and the dropdown with additional columns - dataname_first <- isolate(names(data())[[1]]) - common_code_q <- reactive({ req(iv_r()$is_valid()) @@ -616,25 +627,33 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ) # ANL_OUTLIER_EXTENDED is the base table - qenv <- teal.code::eval_code( - qenv, - substitute( - expr = { - ANL_OUTLIER_EXTENDED <- dplyr::left_join( - ANL_OUTLIER, - dplyr::select( - dataname, - dplyr::setdiff(names(dataname), dplyr::setdiff(names(ANL_OUTLIER), join_keys)) - ), - by = join_keys + join_keys <- as.character(teal.data::join_keys(data_obj())[dataname_first, dataname_first]) + + if (length(join_keys) == 1 && join_keys == ".row_id") { + # Dummy join key - single dataset, no join needed + qenv <- teal.code::eval_code(qenv, quote(ANL_OUTLIER_EXTENDED <- ANL_OUTLIER)) + } else { + # Join keys exist - perform left join + qenv <- teal.code::eval_code( + qenv, + substitute( + expr = { + ANL_OUTLIER_EXTENDED <- dplyr::left_join( + ANL_OUTLIER, + dplyr::select( + dataname, + dplyr::setdiff(names(dataname), dplyr::setdiff(names(ANL_OUTLIER), join_keys)) + ), + by = join_keys + ) + }, + env = list( + dataname = as.name(dataname_first), + join_keys = join_keys ) - }, - env = list( - dataname = as.name(dataname_first), - join_keys = as.character(teal.data::join_keys(data())[dataname_first, dataname_first]) ) ) - ) + } qenv <- if (length(categorical_var) > 0) { qenv <- teal.code::eval_code( @@ -1150,7 +1169,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, brushing = TRUE ) - choices <- reactive(teal.transform::variable_choices(data()[[dataname_first]])) + choices <- reactive(teal.transform::variable_choices(data_obj()[[dataname_first]])) observeEvent(common_code_q(), { ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] From 21a016d377248c04be08bc3f62ba7d5957a972c0 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 10 Jul 2025 09:44:02 +0200 Subject: [PATCH 2/4] bring prefixes Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_outliers.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 4a3040f5e..146ef20d9 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -443,11 +443,11 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, data_obj <- reactive({ obj <- data() - if (length(join_keys(obj)) == 0) { + if (length(teal.data::join_keys(obj)) == 0) { if (!".row_id" %in% names(obj[[dataname_first]])) { obj[[dataname_first]]$.row_id <- seq_len(nrow(obj[[dataname_first]])) } - join_keys(obj) <- join_keys(join_key(dataname_first, dataname_first, ".row_id")) + teal.data::join_keys(obj) <- teal.data::join_keys(teal.data::join_key(dataname_first, dataname_first, ".row_id")) } obj }) From f7713d230bd04d8b8aace260590b921d1af25549 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 10 Jul 2025 13:27:04 +0200 Subject: [PATCH 3/4] Update R/tm_outliers.R Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_outliers.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 146ef20d9..8e418ff86 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -447,7 +447,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, if (!".row_id" %in% names(obj[[dataname_first]])) { obj[[dataname_first]]$.row_id <- seq_len(nrow(obj[[dataname_first]])) } - teal.data::join_keys(obj) <- teal.data::join_keys(teal.data::join_key(dataname_first, dataname_first, ".row_id")) + teal.data::join_keys(obj) <- + teal.data::join_keys(teal.data::join_key(dataname_first, dataname_first, ".row_id")) } obj }) From 45a48cf03d3d761e139a7c951ec9ae0b037d7cf7 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:29:08 +0000 Subject: [PATCH 4/4] [skip style] [skip vbump] Restyle files --- R/tm_outliers.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 8e418ff86..38a137932 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -447,8 +447,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, if (!".row_id" %in% names(obj[[dataname_first]])) { obj[[dataname_first]]$.row_id <- seq_len(nrow(obj[[dataname_first]])) } - teal.data::join_keys(obj) <- - teal.data::join_keys(teal.data::join_key(dataname_first, dataname_first, ".row_id")) + teal.data::join_keys(obj) <- + teal.data::join_keys(teal.data::join_key(dataname_first, dataname_first, ".row_id")) } obj })