R/chk.R

Defines functions chk_flob chk_exint

# remove file once flobr 0.2.1 on CRAN
chk_exint <- function(x, x_name = NULL) {
  if (vld_exint(x)) {
    return(invisible())
  }
  if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))

  chk_s3_class(x, "exint", x_name = x_name)
  chk_scalar(x, x_name = x_name)
  chk_named(x, x_name = x_name)
  chk_s3_class(x[[1]], "integer", x_name = p0("Element of ", x_name))
  chk_no_missing(x[[1]], x_name = p0("Element of ", x_name))
}

chk_flob <- function(x, old = FALSE, x_name = NULL) {
  if (vld_flob(x, old = old)) {
    return(invisible())
  }

  if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))

  chk_s3_class(x, "flob", x_name = x_name)
  chk_scalar(x, x_name = x_name)

  exint <- unlist(x)
  exint <- try(unserialize(exint), silent = TRUE)
  if (inherits(exint, "try-error")) {
    abort_chk(x_name, " must be a blob of a serialized object.")
  }

  if (!vld_false(old)) class(exint) <- "exint"
  chk_exint(exint, x_name = paste("serialized element of", x_name))
}

Try the dbflobr package in your browser

Any scripts or data that you put into this service are public.

dbflobr documentation built on Aug. 20, 2022, 1:06 a.m.