Skip to content

Commit

Permalink
Extend validate_has_data to accept vector input (#962)
Browse files Browse the repository at this point in the history
Closes insightsengineering/teal.modules.general#600

---------

Signed-off-by: Vedha Viyash <[email protected]>
Co-authored-by: Aleksander Chlebowski <[email protected]>
  • Loading branch information
vedhav and chlebowa authored Nov 20, 2023
1 parent d4bab67 commit fcca8ec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal 0.14.0.9018
# teal 0.14.0.9019

### New features

Expand Down
6 changes: 2 additions & 4 deletions R/validations.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ validate_has_data <- function(x,
complete = FALSE,
allow_inf = TRUE,
msg = NULL) {
stopifnot(
"Please provide a character vector in msg argument of validate_has_data." = is.character(msg) || is.null(msg)
)
validate(need(!is.null(x) && is.data.frame(x), "No data left."))
checkmate::assert_string(msg, null.ok = TRUE)
checkmate::assert_data_frame(x)
if (!is.null(min_nrow)) {
if (complete) {
complete_index <- stats::complete.cases(x)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-validate_has_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ testthat::test_that("validate_has_data returns message msg argument is set and c
testthat::test_that("validate_has_data returns throws error with non-character msg input", {
testthat::expect_error(
validate_has_data(data, 10, msg = 1),
"Please provide a character vector in msg argument of validate_has_data."
"Assertion on 'msg' failed: Must be of type 'string' \\(or 'NULL'\\), not 'double'"
)

testthat::expect_error(
validate_has_data(data, 10, msg = TRUE),
"Please provide a character vector in msg argument of validate_has_data."
"Assertion on 'msg' failed: Must be of type 'string' \\(or 'NULL'\\), not 'logical'."
)
})

0 comments on commit fcca8ec

Please sign in to comment.