From 528f8d84a7f78cd5d3943f85c87b28c4f7802d8a Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 21 Jan 2025 12:57:05 +0100 Subject: [PATCH] fix --- R/get_datagrid.R | 9 ++++----- tests/testthat/test-get_datagrid.R | 5 ++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/get_datagrid.R b/R/get_datagrid.R index c675d1471..07e933ba5 100644 --- a/R/get_datagrid.R +++ b/R/get_datagrid.R @@ -792,6 +792,10 @@ get_datagrid.comparisons <- get_datagrid.slopes if (all(grepl('\\".*\\"', parts))) parts <- gsub('"', "", parts, fixed = TRUE) # Make expression ---------- + shortcuts <- c( + "meansd", "sd", "mad", "quartiles", "quartiles2", "zeromax", + "minmax", "terciles", "terciles2", "fivenum", "pretty" + ) if ((is.factor(x) && all(parts %in% levels(x))) || (is.character(x) && all(parts %in% x))) { # Factor # Add quotes around them @@ -799,12 +803,7 @@ get_datagrid.comparisons <- get_datagrid.slopes # Convert to character by_expression <- paste0("as.factor(c(", toString(parts), "))") } else if (length(parts) == 1) { - # Numeric # If one, might be a shortcut. or a sampling request - shortcuts <- c( - "meansd", "sd", "mad", "quartiles", "quartiles2", "zeromax", - "minmax", "terciles", "terciles2", "fivenum", "pretty" - ) if (grepl("sample", parts, fixed = TRUE)) { n_to_sample <- .safe(suppressWarning(as.numeric(trim_ws(gsub("sample", "", parts, fixed = TRUE))))) # nolint # do we have a proper definition of the sample size? If not, error diff --git a/tests/testthat/test-get_datagrid.R b/tests/testthat/test-get_datagrid.R index 78b640390..c9a88b7d6 100644 --- a/tests/testthat/test-get_datagrid.R +++ b/tests/testthat/test-get_datagrid.R @@ -65,7 +65,10 @@ test_that("get_datagrid - terciles, quartiles, mean-sd", { dg <- insight::get_datagrid(m, "Species=[setosa,versicolor]") expect_identical(dim(dg), c(2L, 3L)) - expect_error(insight::get_datagrid(m, "Species=[setosa,wersicolor]")) + expect_error( + insight::get_datagrid(m, "Species=[setosa,wersicolor]"), + regex = "should either indicate" + ) expect_error( insight::get_datagrid(m, "Species=[petosa]"),