Skip to content

Commit

Permalink
Merge pull request #247 from UCD-SERG/update-check_pop_data-to-use-cl…
Browse files Browse the repository at this point in the history
…ass-methods

add class methods to `check_pop_data`
  • Loading branch information
d-morrison authored Sep 6, 2024
2 parents 9375ec0 + 33b0ec7 commit d85b377
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions R/check_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,45 @@
#' @examples
#' library(dplyr)
#' xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>%
#' as_pop_data()
#' check_pop_data(xs_data, verbose = TRUE)
#' as_pop_data()
#' check_pop_data(xs_data, verbose = TRUE)
#'
check_pop_data <- function(pop_data, verbose = FALSE) {
if (!is.data.frame(pop_data)) {
cli::cli_abort(
class = "not a data.frame",
message = c(
"Argument `pop_data` is not a `data.frame()`.",
"Provide a `data.frame()` with cross-sectional serology data per antigen isotype."
"Provide a `data.frame()` with cross-sectional serology
data per antigen isotype."
)
)
}

missing_age <- is.element(attributes(pop_data)$age_var, names(pop_data))
missing_age <- is.element(
pop_data %>% get_age_var(),
pop_data %>% names()
)

if (!missing_age) {
"Argument {.arg pop_data} is missing column {.var {attributes(pop_data)$age_var}} (age, in years)" %>%
"Argument {.arg pop_data} is missing column
{.var {pop_data %>% get_age_var()}}(age, in years)" %>%
cli::cli_abort(class = "missing-var")
}

missing_value <- is.element(attributes(pop_data)$value_var, names(pop_data))
missing_value <- is.element(
pop_data %>% get_value_var(),
pop_data %>% names()
)

if (!missing_value) {
"Argument {.arg pop_data} is missing column {.var {pop_data %>% get_value_var()}} (antibody measurement)" %>%
"Argument {.arg pop_data} is missing column
{.var {pop_data %>% get_value_var()}} (antibody measurement)" %>%
cli::cli_abort(class = "missing-var")
}

if (verbose)
if (verbose) {
cli::cli_inform("data format is as expected.")
}
invisible(NULL)
}
4 changes: 2 additions & 2 deletions man/check_pop_data.Rd

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

0 comments on commit d85b377

Please sign in to comment.