R/shead.R

#' Short Head
#'
#' Returns a more limited head (~10 col) of the object.
#' @param x Vector, matrix, dataframe, or list.
#' @param n_col Vector; Which columns to return. Defaults to 10.
#' @param returnDim Logical; Return dimensions of data? Defaults to TRUE
#' @export
#' @return Head of x.

shead <- function (x, n_col = 1:10, returnDim = TRUE)
{
  if (is.null(dim(x))) {
    if (returnDim)
      cat(paste0("(length: ", length(x), ")", "\n"))
    print(head(x))
  }
  if (!(is.null(dim(x)))) {
    if (ncol(x) < 10) {
      if (returnDim)
        cat(paste0("[", nrow(x), ",", ncol(x), "]", "\n"))
      print(head(x))
    }
    else {
      if (returnDim)
        cat(paste0("[", nrow(x), ",", ncol(x), "]", "\n"))
      print(head(x[, n_col]))
    }
  }
}
ssaxe-usgs/saxey documentation built on May 25, 2019, 5:02 a.m.