Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 21, 2025
1 parent f9acebf commit 528f8d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions R/get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -792,19 +792,18 @@ 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
parts <- paste0("'", parts, "'")
# 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
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-get_datagrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]"),
Expand Down

0 comments on commit 528f8d8

Please sign in to comment.