From 393bd8399ddd2b819b8ca3cea93844c49cf901a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 27 May 2017 11:45:29 +0200 Subject: [PATCH] explicit format.tbl_df() method, closes #263 - The `format.tbl_df()` method is identical to `format.tbl()`, instead of calling `NextMethod()`, to protect against malformed tibbles that inherit from `"tbl_df"` but not `"tbl"`, as created e.g. by `ungroup()` in dplyr 0.5.0 and earlier (#263). --- NAMESPACE | 1 + R/tbl-df.r | 4 ++++ man/formatting.Rd | 3 +++ 3 files changed, 8 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index e8f3d7b45..32a360eda 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,7 @@ S3method(check_names_df,default) S3method(check_names_df,logical) S3method(check_names_df,numeric) S3method(format,tbl) +S3method(format,tbl_df) S3method(format,trunc_mat) S3method(format_v,character) S3method(format_v,default) diff --git a/R/tbl-df.r b/R/tbl-df.r index 64bcc6293..bdba92d10 100644 --- a/R/tbl-df.r +++ b/R/tbl-df.r @@ -14,6 +14,10 @@ format.tbl <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) { format(trunc_mat(x, n = n, width = width, n_extra = n_extra)) } +#' @rdname formatting +#' @export +format.tbl_df <- format.tbl + #' @rdname formatting #' @export print.tbl <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) { diff --git a/man/formatting.Rd b/man/formatting.Rd index 3e266be10..de923e2b4 100644 --- a/man/formatting.Rd +++ b/man/formatting.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/tbl-df.r, R/utils-format.r \name{format.tbl} \alias{format.tbl} +\alias{format.tbl_df} \alias{print.tbl} \alias{print.tbl_df} \alias{formatting} @@ -10,6 +11,8 @@ \usage{ \method{format}{tbl}(x, ..., n = NULL, width = NULL, n_extra = NULL) +\method{format}{tbl_df}(x, ..., n = NULL, width = NULL, n_extra = NULL) + \method{print}{tbl}(x, ..., n = NULL, width = NULL, n_extra = NULL) \method{print}{tbl_df}(x, ..., n = NULL, width = NULL, n_extra = NULL)