Skip to content

Commit

Permalink
Merge pull request #36 from krlmlr/feature/13-options
Browse files Browse the repository at this point in the history
- Use `tibble` prefix for options (#13, #36).
  • Loading branch information
krlmlr authored and Kirill Müller committed Mar 10, 2016
2 parents 9f82619 + 05c4e81 commit 8e917eb
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 15 deletions.
4 changes: 2 additions & 2 deletions R/tbl-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' \code{tbl_df} implements four important base methods:
#'
#' \describe{
#' \item{print}{Only prints the first 10 rows, and the columns that fit on
#' screen}
#' \item{print}{By default only prints the first 10 rows (at most 20), and the
#' columns that fit on screen; see \code{\link{print.tbl_df}}}
#' \item{\code{[}}{Never simplifies (drops), so always returns data.frame}
#' \item{\code{[[}, \code{$}}{Calls \code{\link{.subset2}} directly,
#' so is considerably faster. Throws error if column does not exist.}
Expand Down
39 changes: 39 additions & 0 deletions R/tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,43 @@
#' @import assertthat
#' @importFrom utils head tail
#' @aliases NULL
#' @section Getting started:
#' See \code{\link{tbl_df}} for an introduction,
#' \code{\link{data_frame}} and \code{\link{frame_data}} for construction,
#' \code{\link{as_data_frame}} for coercion,
#' and \code{\link{print.tbl_df}} and \code{\link{glimpse}} for display.
"_PACKAGE"

#' @name tibble-package
#' @section Package options:
#' Display options for \code{tbl_df}, used by \code{\link{trunc_mat}} and
#' (indirectly) by \code{\link{print.tbl_df}}.
#' \describe{
(op.tibble <- list(
#' \item{\code{tibble.print_max}}{Row number threshold: Maximum number of rows
#' printed. Set to \code{Inf} to always print all rows. Default: 20.}
tibble.print_max = 20L,

#' \item{\code{tibble.print_min}}{Number of rows printed if row number
#' threshold is exceeded. Default: 10.}
tibble.print_min = 10L,

#' \item{\code{tibble.width}}{Output width. Default: \code{NULL} (use
#' \code{width} option).}
tibble.width = NULL
#' }
))

tibble_opt <- function(x) {
x_tibble <- paste0("tibble.", x)
res <- getOption(x_tibble)
if (!is.null(res))
return(res)

x_dplyr <- paste0("dplyr.", x)
res <- getOption(x_dplyr)
if (!is.null(res))
return(res)

op.tibble[[x_tibble]]
}
16 changes: 9 additions & 7 deletions R/utils-format.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#'
#' @param x Object to show.
#' @param n Number of rows to show. If \code{NULL}, the default, will print
#' all rows if less than option \code{dplyr.print_max}. Otherwise, will
#' print \code{dplyr.print_min}
#' all rows if less than option \code{tibble.print_max}. Otherwise, will
#' print \code{tibble.print_min} rows.
#' @param width Width of text output to generate. This defaults to NULL, which
#' means use \code{getOption("width")} and only display the columns that
#' fit on one screen. You can also set \code{options(dplyr.width = Inf)} to
#' means use \code{getOption("tibble.width")} or (if also NULL)
#' \code{getOption("width")}; the latter displays only the columns that
#' fit on one screen. You can also set \code{options(tibble.width = Inf)} to
#' override this default and always print all columns.
#' @seealso \link{tibble-package}
#' @keywords internal
#' @examples
#' dim_desc(mtcars)
Expand Down Expand Up @@ -38,8 +40,8 @@ trunc_mat <- function(x, n = NULL, width = NULL, n_extra = 100) {
rows <- nrow(x)

if (is.null(n)) {
if (is.na(rows) || rows > getOption("dplyr.print_max", 20L)) {
n <- getOption("dplyr.print_min", 10L)
if (is.na(rows) || rows > tibble_opt("print_max")) {
n <- tibble_opt("print_min")
} else {
n <- rows
}
Expand All @@ -49,7 +51,7 @@ trunc_mat <- function(x, n = NULL, width = NULL, n_extra = 100) {
var_types <- vapply(df, type_sum, character(1))
var_names <- names(df)

width <- width %||% getOption("dplyr.width", NULL) %||% getOption("width")
width <- width %||% tibble_opt("width") %||% getOption("width")
if (ncol(df) == 0 || nrow(df) == 0) {
shrunk <- list(table = NULL, extra = setNames(var_types, var_names))
} else {
Expand Down
12 changes: 8 additions & 4 deletions man/formatting.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/tbl_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/tibble-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e917eb

Please sign in to comment.