4

In the dplyr package they talk about tbl, how one can join them and so on.

I have looked everywhere for an explanation for tbl but can't find anything useful.

I suspect it is a term that is not just used in the dplyr package, but just in case I will let you know that bumped into it when working with dplyr.

I don't know what it means so my question is:

What does tbl stand for (either in the dplyr package or in general)?

Mus
  • 7,290
  • 24
  • 86
  • 130
Elin
  • 71
  • 1
  • 1
  • 9
  • I spent 10 minutes trying to find useful examples and finally found that I needed quotes around the table name for it to return the table data from database --> tbl(con,"tableName"). The documentation hasn't improved over the last few years. – Andrew Borst Mar 26 '21 at 12:21

3 Answers3

4

tbl = table

in dlplyr there are several types of tables :

join ==> Join two tbls together.

join.tbl_df ==> Join data frame tbls.

join.tbl_dt ==> Join data table tbls.

join.tbl_sql ==> Join sql tbls.

Zahiro Mor
  • 1,708
  • 1
  • 16
  • 30
1

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.

qwr
  • 9,525
  • 5
  • 58
  • 102
1

I think it's a tibble.

The tbl_df class is a subclass of data.frame, created in order to have different default behaviour. The colloquial term "tibble" refers to a data frame that has the tbl_df class. Tibble is the central data structure for the set of packages known as the tidyverse, including dplyr, ggplot2, tidyr, and readr.

peteypolo
  • 11
  • 1