as_tibble() functions, and the low-level
new_tibble() constructor, have undergone a major overhaul to improve consistency. We suspect that package code will be affected more than analysis code.
To improve compatibility with existing code, breaking changes were reduced to a minimum and in some cases replaced with a warning that appears once per session. Call
tibble:::scoped_lifecycle_errors() when updating your packages or scripts to the new semantics API to turn these warnings into errors. The compatibility code will be removed in tibble 3.0.0.
All optional arguments have moved past the ellipsis, and must be specified as named arguments. This affects mostly the
nunnamed still works (with a warning).
new_tibble()has been optimized for performance, the function no longer strips dimensions from 1d arrays and no longer checks correctness of names or column lengths. (It still checks if the object is named, except for zero-length input.) Use the new
validate_tibble()if you need these checks (#471).
new_tibble()is now mandatory. The
classargument replaces the now deprecated
subclassargument, the latter will be supported quietly for some time (#518).
Setting names on a tibble via
names(df) <- ...now also requires minimal names, otherwise a warning is issued once per session (#466).
as_tibble(), checking names is also enabled by default, even for tibbles, matrices and other matrix-like objects: names must exist,
NAnames are not allowed. Coercing a matrix without column names will trigger a warning once per session. (This corresponds to the
"minimal"checks described below.).
as_tibble()has been deprecated, see below for alternatives. (The
as_tibble.tbl_df()method has been removed, the
as_tibble.data.frame()method will be used for tibbles.)
as_tibble()always checks that all columns are 1D or 2D vectors and not of type
POSIXlt, even with
validate = FALSE(which is now deprecated).
as_tibble()on a vector now warns once per session. Use
enframe(name = NULL)for converting a vector to a one-column tibble, or
enframe()for converting a named vector to a two-column tibble.
frame_data()are soft-deprecated, please use
as_data_frame()are officially deprecated and not generic anymore, please use/implement
as_tibble.matrix()) strip row names by default. Code that relies on tibbles keeping row names now will see:
- a different result when calling
- rows full of
NAvalues when subsetting rows with with a character vector, e.g.
as_tibble(mtcars)["Mazda RX4", ].
pkgconfig::set_config("tibble::rownames", NA)to revert to the old behavior of keeping row names. Packages that import tibble can call
- a different result when calling
as_tibble()drops extra classes, in particular
as_tibble.grouped_df()now removes grouping (#535).
column_to_rownames()now always coerces to a data frame, because row names are no longer supported in tibbles (#114).
*_rownames()functions, the first argument has been renamed to
.datafor consistency (#412).
Subsetting one row with
[..., , drop = TRUE]returns a tibble (#442).
print.tbl_df()method has been removed, the
print.tbl()method handles printing (#519).
tibble()supports columns that are matrices or data frames (#416).
as_tibble()allows specifying the expected number of rows explicitly, even if it's evident from the data. This allows writing more defensive code.
Column name repair has more direct support, via the new
as_tibble(). It takes the following values:
"minimal": No name repair or checks, beyond basic existence.
"unique": Make sure names are unique and not empty.
"check_unique": (default value), no name repair, but check they are
"universal": Make the names
- a function: apply custom name repair (e.g.,
.name_repair = make.namesor
.name_repair = ~make.names(., unique = TRUE)for names in the style of base R).
as_tibble()is deprecated but supported (emits a message once per session). Use
.name_repair = "minimal"instead of
validate = FALSE, and
.name_repair = "check_unique"instead of
validate = TRUE. If you need to support older versions of tibble, pass both
validatearguments in a consistent way, no message will be emitted in this case (#469, @jennybc).
Row name handling is stricter. Row names are never (and never were) supported in
new_tibble(), and are now stripped by default in
NULL: remove row names (default),
NA: keep row names,
- A string: the name of the new column that will contain the existing row names,
which are no longer present in the result.
The old default can be restored by calling
pkgconfig::set_config("tibble::rownames", NA), this also works for packages that import tibble.
as_tibble()now also strip the
"dim"attribute from columns that are one-dimensional arrays. (
tibble()already did this before.)
as_tibble()implementation forward all extra arguments and
as_tibble.list()where they are handled. This means that the common
.name_repaircan be used for all inputs. We suggest that your implementations of this method do the same.
name = NULL) and
deframe()now support one-column tibbles (#449).
validate_tibble()checks a tibble for internal consistency (#471).
- Added experimental
view()function that always returns its input invisibly and calls
utils::View()only in interactive mode (#373).
tidy_names()helpers the list of new names using a bullet list with at most six items (#406).
A one-character ellipse (
cli::symbol$ellipsis) is printed instead of
"..."where available, this affects
glimpse()output and truncated lists (#403).
Column names and types are now formatted identically with
tidy_names()quotes variable names when reporting on repair (#407).
All error messages now follow the tidyverse style guide (#223).
Lazy tibbles with exactly 10 rows no longer show "...with more rows" (#371).
glimpse()shows information obtained from
tbl_sum(), e.g. grouping information for
grouped_dffrom dplyr (#550).
glimpse()takes coloring into account when computing column width, the output is no longer truncated prematurely when coloring is enabled.
print.tbl_df()with a negative value for
nbehaves as if
nwas omitted (#371).
fansi::strwrap_ctl()instead of own string wrapping routine.
tibble()uses recycled values during construction but unrecycled values for validation.
tibble()is now faster for very wide tibbles.
Subsetting with the
[operator is faster (#544).