From b45a51797066555c8524ffead629e40edbc9b582 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 10 Oct 2024 22:04:46 +0200 Subject: [PATCH] add test --- R/row_count.R | 5 +++++ tests/testthat/test-row_count.R | 1 + 2 files changed, 6 insertions(+) diff --git a/R/row_count.R b/R/row_count.R index b7e249755..d63596472 100644 --- a/R/row_count.R +++ b/R/row_count.R @@ -75,6 +75,11 @@ row_count <- function(data, data <- .coerce_to_dataframe(data[select]) + # check if we have a data framme with at least two columns + if (nrow(data) < 1) { + insight::format_error("`data` must be a data frame with at least one row.") + } + # check if we have a data framme with at least two columns if (ncol(data) < 2) { insight::format_error("`data` must be a data frame with at least two numeric columns.") diff --git a/tests/testthat/test-row_count.R b/tests/testthat/test-row_count.R index 312eb3415..91b7ddd49 100644 --- a/tests/testthat/test-row_count.R +++ b/tests/testthat/test-row_count.R @@ -23,6 +23,7 @@ test_that("row_count, errors or messages", { expect_error(expect_warning(row_count(iris, select = "abc")), regex = "must be a valid") expect_error(expect_warning(row_count(iris, select = "abc", count = 3)), regex = "No columns") expect_error(row_count(iris[1], count = 3), regex = "with at least") + expect_error(row_count(d_mn[-c(1:4), , drop = FALSE], count = 2), regex = "one row") }) test_that("row_count, exact match", {