From 9ee8824828170401d34266c6dfdf400a6d2b9844 Mon Sep 17 00:00:00 2001 From: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> Date: Mon, 22 May 2023 11:25:12 +0200 Subject: [PATCH] fix describe_distribution error --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/plot.describe_distribution.R | 4 ++-- tests/testthat/test-plot.describe_distribution.R | 6 ++++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa6621996..111cc5cdc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.7.5.5 +Version: 0.7.5.6 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 2e6b6967f..6b00ef60a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,9 @@ * Fixes issue in `plot.binned_residuals()` for models whose residuals were completely inside error bounds. + +* `plot()` now works when using it on the output of `describe_distribution()` with + a `select` argument of length 1. # see 0.7.5 diff --git a/R/plot.describe_distribution.R b/R/plot.describe_distribution.R index a6e3921b2..4f3012b72 100644 --- a/R/plot.describe_distribution.R +++ b/R/plot.describe_distribution.R @@ -1,6 +1,6 @@ #' @export data_plot.parameters_distribution <- function(x, data = NULL, ...) { - if (nrow(x) == 1) { + if (nrow(x) == 1 && is.null(x$Variable)) { dataplot <- data.frame( x = data, stringsAsFactors = FALSE @@ -71,7 +71,7 @@ plot.see_parameters_distribution <- function(x, # only keep variables used in "describe_distribution()" if (!is.null(x$Variable)) { - data <- data[x$Variable] + data <- data[, x$Variable, drop = FALSE] } if (!inherits(x, "data_plot")) { diff --git a/tests/testthat/test-plot.describe_distribution.R b/tests/testthat/test-plot.describe_distribution.R index 931fa1054..900246509 100644 --- a/tests/testthat/test-plot.describe_distribution.R +++ b/tests/testthat/test-plot.describe_distribution.R @@ -3,4 +3,10 @@ test_that("`plot.see_parameters_distribution()` works", { x <- sample(1:100, 1000, replace = TRUE) result <- datawizard::describe_distribution(x) expect_s3_class(plot(result), "gg") + + result <- datawizard::describe_distribution(iris) + expect_true(all(vapply(plot(result), inherits, "gg", FUN.VALUE = logical(1L)))) + + result <- datawizard::describe_distribution(iris, select = "Sepal.Length") + expect_true(all(vapply(plot(result), inherits, "gg", FUN.VALUE = logical(1L)))) })