From 2b52f7cb92f204dc6422b66a8b4f87aa478a745c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:01:42 +0000 Subject: [PATCH 01/13] Initial plan From f8a12081d25f91c0c045438d8834b938cc7bf28e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:10:38 +0000 Subject: [PATCH 02/13] Fix estimate_density plotting with vector input and group_by Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- R/plot.estimate_density.R | 33 +++++++++++++++++---- tests/testthat/test-plot.estimate_density.R | 12 ++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 51dac57dc..0e689572c 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -11,6 +11,16 @@ data_plot.estimate_density <- function( if (!"Parameter" %in% names(dataplot)) { dataplot$Parameter <- "Distribution" } + + # Handle case where Parameter column exists but is empty or malformed + if ("Parameter" %in% names(dataplot)) { + if (length(dataplot$Parameter) == 0 || + all(is.na(dataplot$Parameter)) || + all(dataplot$Parameter == "") || + length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0) { + dataplot$Parameter <- "Distribution" + } + } # add component and effects columns if (!is.null(data)) { @@ -23,11 +33,19 @@ data_plot.estimate_density <- function( dataplot <- .fix_facet_names(dataplot) - dataplot$Parameter <- factor(dataplot$Parameter) - dataplot$Parameter <- factor( - dataplot$Parameter, - levels = rev(levels(dataplot$Parameter)) - ) + # Safely convert Parameter to factor, ensuring it has valid data + if ("Parameter" %in% names(dataplot) && + length(dataplot$Parameter) > 0 && + !all(is.na(dataplot$Parameter))) { + dataplot$Parameter <- factor(dataplot$Parameter) + dataplot$Parameter <- factor( + dataplot$Parameter, + levels = rev(levels(dataplot$Parameter)) + ) + } else { + # If Parameter column is still problematic, set a default + dataplot$Parameter <- factor("Distribution") + } # summary split_columns <- intersect( @@ -250,6 +268,11 @@ plot.see_estimate_density <- function( p <- p + facet_wrap(~Component, scales = "free", ncol = n_columns) } } + + # Handle Group column for grouped data (e.g., from group_by in estimate_density) + if ("Group" %in% names(x)) { + p <- p + facet_wrap(~Group, scales = "free", ncol = n_columns) + } p } diff --git a/tests/testthat/test-plot.estimate_density.R b/tests/testthat/test-plot.estimate_density.R index d197600ea..578dc38f2 100644 --- a/tests/testthat/test-plot.estimate_density.R +++ b/tests/testthat/test-plot.estimate_density.R @@ -9,6 +9,18 @@ test_that("`plot.see_estimate_density()` works", { }) +test_that("`plot.see_estimate_density()` works with group_by and vector input", { + skip_if_not_installed("bayestestR") + + # Test case that was failing: vector input with group_by + df <- bayestestR::estimate_density(iris[c("Species", "Petal.Width")], group_by = "Species") + + # This should not error + expect_no_error(p <- plot(df)) + expect_s3_class(p, "gg") +}) + + test_that("`plot.see_estimate_density()`, adding prior layers works", { skip_if_not_installed("curl") skip_if_offline() From 1bb025f8979bf12b5b89e6a573f9c9e57e035d2e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:13:29 +0000 Subject: [PATCH 03/13] Improved estimate_density fix with length-safe parameter handling Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- R/plot.estimate_density.R | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 0e689572c..ec5a59a0c 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -14,11 +14,12 @@ data_plot.estimate_density <- function( # Handle case where Parameter column exists but is empty or malformed if ("Parameter" %in% names(dataplot)) { + # Check for various problematic conditions if (length(dataplot$Parameter) == 0 || all(is.na(dataplot$Parameter)) || all(dataplot$Parameter == "") || length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0) { - dataplot$Parameter <- "Distribution" + dataplot$Parameter <- rep("Distribution", nrow(dataplot)) } } @@ -36,6 +37,7 @@ data_plot.estimate_density <- function( # Safely convert Parameter to factor, ensuring it has valid data if ("Parameter" %in% names(dataplot) && length(dataplot$Parameter) > 0 && + length(dataplot$Parameter) == nrow(dataplot) && !all(is.na(dataplot$Parameter))) { dataplot$Parameter <- factor(dataplot$Parameter) dataplot$Parameter <- factor( @@ -43,8 +45,8 @@ data_plot.estimate_density <- function( levels = rev(levels(dataplot$Parameter)) ) } else { - # If Parameter column is still problematic, set a default - dataplot$Parameter <- factor("Distribution") + # If Parameter column is still problematic, set a default with correct length + dataplot$Parameter <- factor(rep("Distribution", nrow(dataplot))) } # summary @@ -270,8 +272,9 @@ plot.see_estimate_density <- function( } # Handle Group column for grouped data (e.g., from group_by in estimate_density) - if ("Group" %in% names(x)) { - p <- p + facet_wrap(~Group, scales = "free", ncol = n_columns) + # Only add facets if not already faceting by other variables and if we have groups + if ("Group" %in% names(x) && is.null(n_columns)) { + p <- p + facet_wrap(~Group, scales = "free") } p From 45da86ffa02d6a76ddab9b9e82bbef61cc3d34fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:33:32 +0000 Subject: [PATCH 04/13] Refactor complex conditionals and add vdiffr visual test Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- R/plot.estimate_density.R | 28 ++++++++++++++------- tests/testthat/test-plot.estimate_density.R | 7 ++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index ec5a59a0c..9fb89205d 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -14,11 +14,16 @@ data_plot.estimate_density <- function( # Handle case where Parameter column exists but is empty or malformed if ("Parameter" %in% names(dataplot)) { - # Check for various problematic conditions - if (length(dataplot$Parameter) == 0 || - all(is.na(dataplot$Parameter)) || - all(dataplot$Parameter == "") || - length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0) { + # Check for various problematic conditions with descriptive variables + parameter_is_empty <- length(dataplot$Parameter) == 0 + parameter_all_na <- all(is.na(dataplot$Parameter)) + parameter_all_empty_strings <- all(dataplot$Parameter == "") + parameter_no_unique_values <- length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0 + + parameter_is_problematic <- parameter_is_empty || parameter_all_na || + parameter_all_empty_strings || parameter_no_unique_values + + if (parameter_is_problematic) { dataplot$Parameter <- rep("Distribution", nrow(dataplot)) } } @@ -35,10 +40,15 @@ data_plot.estimate_density <- function( dataplot <- .fix_facet_names(dataplot) # Safely convert Parameter to factor, ensuring it has valid data - if ("Parameter" %in% names(dataplot) && - length(dataplot$Parameter) > 0 && - length(dataplot$Parameter) == nrow(dataplot) && - !all(is.na(dataplot$Parameter))) { + parameter_column_exists <- "Parameter" %in% names(dataplot) + parameter_has_data <- length(dataplot$Parameter) > 0 + parameter_length_matches <- length(dataplot$Parameter) == nrow(dataplot) + parameter_not_all_na <- !all(is.na(dataplot$Parameter)) + + parameter_is_valid_for_factor <- parameter_column_exists && parameter_has_data && + parameter_length_matches && parameter_not_all_na + + if (parameter_is_valid_for_factor) { dataplot$Parameter <- factor(dataplot$Parameter) dataplot$Parameter <- factor( dataplot$Parameter, diff --git a/tests/testthat/test-plot.estimate_density.R b/tests/testthat/test-plot.estimate_density.R index 578dc38f2..0d5758bf3 100644 --- a/tests/testthat/test-plot.estimate_density.R +++ b/tests/testthat/test-plot.estimate_density.R @@ -11,6 +11,7 @@ test_that("`plot.see_estimate_density()` works", { test_that("`plot.see_estimate_density()` works with group_by and vector input", { skip_if_not_installed("bayestestR") + skip_if_not_installed("vdiffr") # Test case that was failing: vector input with group_by df <- bayestestR::estimate_density(iris[c("Species", "Petal.Width")], group_by = "Species") @@ -18,6 +19,12 @@ test_that("`plot.see_estimate_density()` works with group_by and vector input", # This should not error expect_no_error(p <- plot(df)) expect_s3_class(p, "gg") + + # Visual snapshot test + vdiffr::expect_doppelganger( + title = "plot.estimate_density with group_by and vector input", + fig = plot(df) + ) }) From 6b4b97dff0ea55e9fb81447be791f1fb52bd7c06 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:44:45 +0000 Subject: [PATCH 05/13] Fix boolean variable naming to follow is_/has_/can_ convention Co-authored-by: IndrajeetPatil <11330453+IndrajeetPatil@users.noreply.github.com> --- R/plot.estimate_density.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 9fb89205d..45f2ddf3d 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -15,15 +15,15 @@ data_plot.estimate_density <- function( # Handle case where Parameter column exists but is empty or malformed if ("Parameter" %in% names(dataplot)) { # Check for various problematic conditions with descriptive variables - parameter_is_empty <- length(dataplot$Parameter) == 0 - parameter_all_na <- all(is.na(dataplot$Parameter)) - parameter_all_empty_strings <- all(dataplot$Parameter == "") - parameter_no_unique_values <- length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0 + is_parameter_empty <- length(dataplot$Parameter) == 0 + is_parameter_all_na <- all(is.na(dataplot$Parameter)) + has_parameter_all_empty_strings <- all(dataplot$Parameter == "") + has_parameter_no_unique_values <- length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0 - parameter_is_problematic <- parameter_is_empty || parameter_all_na || - parameter_all_empty_strings || parameter_no_unique_values + is_parameter_problematic <- is_parameter_empty || is_parameter_all_na || + has_parameter_all_empty_strings || has_parameter_no_unique_values - if (parameter_is_problematic) { + if (is_parameter_problematic) { dataplot$Parameter <- rep("Distribution", nrow(dataplot)) } } @@ -40,15 +40,15 @@ data_plot.estimate_density <- function( dataplot <- .fix_facet_names(dataplot) # Safely convert Parameter to factor, ensuring it has valid data - parameter_column_exists <- "Parameter" %in% names(dataplot) - parameter_has_data <- length(dataplot$Parameter) > 0 - parameter_length_matches <- length(dataplot$Parameter) == nrow(dataplot) - parameter_not_all_na <- !all(is.na(dataplot$Parameter)) + has_parameter_column <- "Parameter" %in% names(dataplot) + has_parameter_data <- length(dataplot$Parameter) > 0 + has_parameter_length_match <- length(dataplot$Parameter) == nrow(dataplot) + has_parameter_not_all_na <- !all(is.na(dataplot$Parameter)) - parameter_is_valid_for_factor <- parameter_column_exists && parameter_has_data && - parameter_length_matches && parameter_not_all_na + is_parameter_valid_for_factor <- has_parameter_column && has_parameter_data && + has_parameter_length_match && has_parameter_not_all_na - if (parameter_is_valid_for_factor) { + if (is_parameter_valid_for_factor) { dataplot$Parameter <- factor(dataplot$Parameter) dataplot$Parameter <- factor( dataplot$Parameter, From 3d638a27182451d5d8a9a471580f1c359c18b141 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:50:49 +0200 Subject: [PATCH 06/13] add snapshot --- ...density-with-group-by-and-vector-input.svg | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/testthat/_snaps/plot.estimate_density/plot-estimate-density-with-group-by-and-vector-input.svg diff --git a/tests/testthat/_snaps/plot.estimate_density/plot-estimate-density-with-group-by-and-vector-input.svg b/tests/testthat/_snaps/plot.estimate_density/plot-estimate-density-with-group-by-and-vector-input.svg new file mode 100644 index 000000000..b674f38b6 --- /dev/null +++ b/tests/testthat/_snaps/plot.estimate_density/plot-estimate-density-with-group-by-and-vector-input.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.5 +1.0 +1.5 +2.0 +2.5 +x +y +plot.estimate_density with group_by and vector input + + From 3c99f2ea8b5a3dd7da7d3bf6cff76e77d8105640 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:55:58 +0200 Subject: [PATCH 07/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- R/plot.estimate_density.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 45f2ddf3d..2ddee0da3 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -11,7 +11,6 @@ data_plot.estimate_density <- function( if (!"Parameter" %in% names(dataplot)) { dataplot$Parameter <- "Distribution" } - # Handle case where Parameter column exists but is empty or malformed if ("Parameter" %in% names(dataplot)) { # Check for various problematic conditions with descriptive variables From aa4c89ff80508689490be2112a2b1ebc56fb64d3 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:05 +0200 Subject: [PATCH 08/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- R/plot.estimate_density.R | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 2ddee0da3..a382942fb 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -17,11 +17,16 @@ data_plot.estimate_density <- function( is_parameter_empty <- length(dataplot$Parameter) == 0 is_parameter_all_na <- all(is.na(dataplot$Parameter)) has_parameter_all_empty_strings <- all(dataplot$Parameter == "") - has_parameter_no_unique_values <- length(unique(dataplot$Parameter[!is.na(dataplot$Parameter)])) == 0 - - is_parameter_problematic <- is_parameter_empty || is_parameter_all_na || - has_parameter_all_empty_strings || has_parameter_no_unique_values - + has_parameter_no_unique_values <- length(unique(dataplot$Parameter[ + !is.na(dataplot$Parameter) + ])) == + 0 + + is_parameter_problematic <- is_parameter_empty || + is_parameter_all_na || + has_parameter_all_empty_strings || + has_parameter_no_unique_values + if (is_parameter_problematic) { dataplot$Parameter <- rep("Distribution", nrow(dataplot)) } From 6c841cbce714c1fb22a7a56adc74c30315ee516c Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:11 +0200 Subject: [PATCH 09/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- R/plot.estimate_density.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index a382942fb..0362a0e76 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -48,10 +48,12 @@ data_plot.estimate_density <- function( has_parameter_data <- length(dataplot$Parameter) > 0 has_parameter_length_match <- length(dataplot$Parameter) == nrow(dataplot) has_parameter_not_all_na <- !all(is.na(dataplot$Parameter)) - - is_parameter_valid_for_factor <- has_parameter_column && has_parameter_data && - has_parameter_length_match && has_parameter_not_all_na - + + is_parameter_valid_for_factor <- has_parameter_column && + has_parameter_data && + has_parameter_length_match && + has_parameter_not_all_na + if (is_parameter_valid_for_factor) { dataplot$Parameter <- factor(dataplot$Parameter) dataplot$Parameter <- factor( From b313d8fa2120cb0cbb6ef9ad514f55180ac7fc8a Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:19 +0200 Subject: [PATCH 10/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- R/plot.estimate_density.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/plot.estimate_density.R b/R/plot.estimate_density.R index 0362a0e76..d8b1f34e8 100644 --- a/R/plot.estimate_density.R +++ b/R/plot.estimate_density.R @@ -286,7 +286,6 @@ plot.see_estimate_density <- function( p <- p + facet_wrap(~Component, scales = "free", ncol = n_columns) } } - # Handle Group column for grouped data (e.g., from group_by in estimate_density) # Only add facets if not already faceting by other variables and if we have groups if ("Group" %in% names(x) && is.null(n_columns)) { From 40bbd0c0c3f05de292e9a74afe153875ba6a4b89 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:28 +0200 Subject: [PATCH 11/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/testthat/test-plot.estimate_density.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-plot.estimate_density.R b/tests/testthat/test-plot.estimate_density.R index 0d5758bf3..c7f80bcc2 100644 --- a/tests/testthat/test-plot.estimate_density.R +++ b/tests/testthat/test-plot.estimate_density.R @@ -12,7 +12,6 @@ test_that("`plot.see_estimate_density()` works", { test_that("`plot.see_estimate_density()` works with group_by and vector input", { skip_if_not_installed("bayestestR") skip_if_not_installed("vdiffr") - # Test case that was failing: vector input with group_by df <- bayestestR::estimate_density(iris[c("Species", "Petal.Width")], group_by = "Species") From 2bddc819f5943aa77bebdc49cb91b597736dcd42 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:37 +0200 Subject: [PATCH 12/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/testthat/test-plot.estimate_density.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-plot.estimate_density.R b/tests/testthat/test-plot.estimate_density.R index c7f80bcc2..830bb3575 100644 --- a/tests/testthat/test-plot.estimate_density.R +++ b/tests/testthat/test-plot.estimate_density.R @@ -13,8 +13,11 @@ test_that("`plot.see_estimate_density()` works with group_by and vector input", skip_if_not_installed("bayestestR") skip_if_not_installed("vdiffr") # Test case that was failing: vector input with group_by - df <- bayestestR::estimate_density(iris[c("Species", "Petal.Width")], group_by = "Species") - + df <- bayestestR::estimate_density( + iris[c("Species", "Petal.Width")], + group_by = "Species" + ) + # This should not error expect_no_error(p <- plot(df)) expect_s3_class(p, "gg") From e08aa45e4f817c75176dcf43c9ae26e217f0492a Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Mon, 15 Sep 2025 21:56:46 +0200 Subject: [PATCH 13/13] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- tests/testthat/test-plot.estimate_density.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-plot.estimate_density.R b/tests/testthat/test-plot.estimate_density.R index 830bb3575..c6cd3cc86 100644 --- a/tests/testthat/test-plot.estimate_density.R +++ b/tests/testthat/test-plot.estimate_density.R @@ -21,7 +21,6 @@ test_that("`plot.see_estimate_density()` works with group_by and vector input", # This should not error expect_no_error(p <- plot(df)) expect_s3_class(p, "gg") - # Visual snapshot test vdiffr::expect_doppelganger( title = "plot.estimate_density with group_by and vector input",