Skip to content

Commit

Permalink
add class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisorwa committed Sep 2, 2024
1 parent 9375ec0 commit c2110b6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions R/check_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @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)) {
Expand All @@ -21,21 +21,28 @@ check_pop_data <- function(pop_data, verbose = FALSE) {
)
}

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)" %>%

Check warning on line 30 in R/check_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/check_pop_data.R,line=30,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 104 characters.
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)" %>%

Check warning on line 40 in R/check_pop_data.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/check_pop_data.R,line=40,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 113 characters.
cli::cli_abort(class = "missing-var")
}

if (verbose)
if (verbose) {
cli::cli_inform("data format is as expected.")
}
invisible(NULL)
}

0 comments on commit c2110b6

Please sign in to comment.