Skip to content

Commit

Permalink
feat: extend validate_has_data to accept vector input
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Nov 10, 2023
1 parent 6075555 commit bfa4594
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions R/validations.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Validate that dataset has a minimum number of observations
#'
#' @description `r lifecycle::badge("stable")`
#' @param x a data.frame
#' @param x a data.frame or a vector
#' @param min_nrow minimum number of rows in \code{x}
#' @param complete \code{logical} default \code{FALSE} when set to \code{TRUE} then complete cases are checked.
#' @param allow_inf \code{logical} default \code{TRUE} when set to \code{FALSE} then error thrown if any values are
Expand Down Expand Up @@ -46,7 +46,15 @@ validate_has_data <- function(x,
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."))

validate(need(is.vector(x) || is.data.frame(x), "Input must be a vector or a data frame."))

if (is.vector(x) && !is.null(x)) {
x <- data.frame(x)
}

validate(need(!is.null(x), "No data left."))

if (!is.null(min_nrow)) {
if (complete) {
complete_index <- stats::complete.cases(x)
Expand Down
2 changes: 1 addition & 1 deletion man/validate_has_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bfa4594

Please sign in to comment.