R/validators.R

Defines functions validate_tbl_time assert_index_exists_in_colnames assert_index_class_is_allowed

# Main validator
validate_tbl_time <- function(x) {
  assert_index_exists_in_colnames(x)
  assert_index_class_is_allowed(x)
  x
}

assert_index_exists_in_colnames <- function(x) {
  index_char <- get_index_char(x)
  assertthat::assert_that(
    index_char %in% colnames(x),
    msg = "Specified `index` is not a column of x"
  )
}

assert_index_class_is_allowed <- function(x) {
  index_char <- get_index_char(x)
  index_col <- x[[index_char]]
  assertthat::assert_that(
    is_allowed_datetime(index_col),
    msg = "Specified `index` is not time based"
  )
}
DavisVaughan/tibbletime3 documentation built on May 28, 2019, 12:25 p.m.