It is actually quite hard to find information on this topic. The docs for tbl
/is.tbl
give very little information.
To the best of my knowledge, tbl is a generic class for tabular data that dplyr functions take in as data arguments.
Creating a tbl prepents "tbl_" to the class name. From dplyr/tbl.r:
#' Create a "tbl" object
#'
#' `tbl()` is the standard constructor for tbls. `as.tbl()` coerces,
#' and `is.tbl()` tests.
#'
#' @keywords internal
#' @export
#' @param subclass name of subclass. "tbl" is an abstract base class, so you
#' must supply this value. `tbl_` is automatically prepended to the
#' class name
#' @param object to test/coerce.
#' @param ... For `tbl()`, other fields used by class. For `as.tbl()`,
#' other arguments passed to methods.
#' @examples
#' as.tbl(mtcars)
make_tbl <- function(subclass, ...) {
subclass <- paste0("tbl_", subclass)
structure(list(...), class = c(subclass, "tbl"))
Using any dplyr function (join, select, mutate, etc.) on a data.frame gives back a data.frame.
library(dplyr)
select(mtcars, cyl) %>% class
However, calling a dplyr function on a tbl_df/tibble (see my answer on tibble vs tbl_df) gives back a tbl_df/tibble.
> select(tbl_df(mtcars), cyl) %>% class
[1] "tbl_df" "tbl" "data.frame"
Here we see tbl_df
inherits from tbl
, which inherits from data.frame
.