R/altrep.R

Defines functions vroom_str.default vroom_str.data.frame vroom_str

Documented in vroom_str

#' Structure of objects
#'
#' Similar to `str()` but with more information for Altrep objects.
#'
#' @param x a vector
#' @examples
#' # when used on non-altrep objects altrep will always be false
#' vroom_str(mtcars)
#'
#' mt <- vroom(vroom_example("mtcars.csv"), ",", altrep = c("chr", "dbl"))
#' vroom_str(mt)
#' @export
vroom_str <- function(x) {
  UseMethod("vroom_str")
}

#' @export
vroom_str.data.frame <- function(x) {
  classes <- glue::glue_collapse(glue::single_quote(class(x)), ", ", last = ", and ")
  rows <- nrow(x)
  cols <- ncol(x)

  cat(glue::glue("{classes}: {rows} obs., {cols} vars.:\n\n"), sep = "")
  nms <- names(x)
  for (i in seq_along(x)) {
    cat("$", nms[[i]], ":\t", sep = "")
    vroom_str(x[[i]])
  }
}

#' @export
vroom_str.default <- function(x) {
  cat(vroom_str_(x))
}

Try the vroom package in your browser

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

vroom documentation built on June 14, 2021, 5:09 p.m.