Tibbles in R
The Modern Data Frame
Learn how tibbles improve on traditional data frames with cleaner printing, stricter subsetting, and safer defaults for modern data analysis.
What is a Tibble?
A tibble is a modern reimagining of the classic R data frame. Introduced by the tibble package (part of the tidyverse), tibbles are designed to be lazier and friendlier than traditional data frames.
Why Do Tibbles Exist?
Traditional data frames have some surprising behaviors that can introduce subtle bugs. Tibbles fix three major pain points:
Tibbles in the Tidyverse
Creating Tibbles
There are two primary ways to create a tibble: the tibble() constructor and converting an existing data frame with as_tibble().
Quick Tables with tribble()
The tribble() function lets you define a tibble row by row: perfect for small, hand-entered data that you want to be readable in your code.
The Printing Difference
This is the most immediately visible benefit of tibbles. Compare what happens when you print a large dataset:
Tibble Print Output
Customizing Print Behavior
You can override the default 10-row limit using print() with arguments, or by setting global options:
Stricter Subsetting Rules
Tibbles are more predictable when you extract columns. Here are the two key differences:
data.frame vs tibble
| Feature | data.frame | tibble |
|---|---|---|
| Printing | All rows/columns | First 10 rows + types |
| String handling | Converts to factor (older R) | Keeps as character |
| Partial matching ($) | Allowed silently | Warning + NULL |
| [ ] single column | Returns a vector | Returns a tibble |
| Column referencing | Cannot use earlier cols | Can reference earlier cols |
| Row names | Supported | Discouraged |
How to Start Using Tibbles
Example: Building a Tibble
Example: Subsetting a Tibble
Example: Converting and Inspecting
Common Mistakes
Question 1 of 5
When you print a tibble to the console, what is the default number of rows displayed?
Question 2 of 5
What does tibble[, "col_name"] return, unlike a traditional data frame?
Question 3 of 5
Which function creates a tibble by entering data row by row in a readable format?
Question 4 of 5
What happens when you type my_tibble$n if the only column is named name?
Question 5 of 5
Inside a tibble() call, you can reference a column you just defined on a previous line. What is this feature called?