diff --git a/R/data_summary.R b/R/data_summary.R index 8bb4f3e09..3b02762ec 100644 --- a/R/data_summary.R +++ b/R/data_summary.R @@ -58,6 +58,11 @@ data_summary.default <- function(x, ...) { data_summary.data.frame <- function(x, ..., by = NULL) { dots <- eval(substitute(alist(...))) + # do we have any expression at all? + if (length(dots) == 0) { + insight::format_error("No expressions for calculating summary statistics provided.") + } + if (is.null(by)) { # when we have no grouping, just compute a one-row summary summarise <- .process_datasummary_dots(dots, x) diff --git a/tests/testthat/test-data_summary.R b/tests/testthat/test-data_summary.R index e057cc35a..b82d78095 100644 --- a/tests/testthat/test-data_summary.R +++ b/tests/testthat/test-data_summary.R @@ -131,6 +131,11 @@ test_that("data_summary, errors", { data_summary(iris$Sepal.Width, MW = mean(Sepal.Width), SD = sd(Sepal.Width)), regex = "only works for" ) + # no expressions + expect_error( + data_summary(iris, by = "Species"), + regex = "No expressions for calculating" + ) })