Skip to content

Commit

Permalink
better print in case of no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 12, 2023
1 parent 8c001be commit ae678ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/data_seek.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,9 @@ data_seek <- function(data, pattern, seek = c("names", "labels"), fuzzy = FALSE)

#' @export
print.data_seek <- function(x, ...) {
cat(insight::export_table(x, ...))
if (nrow(x) == 0) {
cat("No matches found.\n")
} else {
cat(insight::export_table(x, ...))
}
}
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/data_seek.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@
1 | Sepal.Length | Sepal.Length
3 | Petal.Length | Petal.Length

---

Code
data_seek(iris, "abc")
Output
No matches found.

1 change: 1 addition & 0 deletions tests/testthat/test-data_seek.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ test_that("data_seek - valid input", {

test_that("data_seek - print", {
expect_snapshot(data_seek(iris, "Length"))
expect_snapshot(data_seek(iris, "abc"))
})

0 comments on commit ae678ef

Please sign in to comment.