tibble glimpse() in R: Compact Transposed Data Preview
The glimpse() function in the tibble package prints a transposed, column-by-column preview of a data frame so you can see every column name, its type, and the first few values on a single screen.
glimpse(mtcars) # default: console width glimpse(iris, width = 60) # narrower for small terminals glimpse(starwars) # handles list-columns mtcars |> glimpse() # pipe-friendly, returns invisibly df |> filter(cyl == 4) |> glimpse() # inspect mid-pipeline glimpse(as_tibble(airquality)) # works on plain data.frames too
Need explanation? Read on for examples and pitfalls.
What glimpse() does in one sentence
glimpse() is a transposed printer for data frames. Instead of showing columns left-to-right and rows top-to-bottom like print(), it puts each column on its own line, so you can see all 60 columns of a wide tibble without horizontal scrolling. Each line shows the column name, its type in angle brackets, and as many values as fit in the console width.
It belongs to the tibble package and is re-exported by dplyr, so library(tibble) or library(dplyr) both bring it into scope. The function returns its input invisibly, which makes it safe to drop anywhere inside a pipeline without breaking the chain.
Syntax
glimpse() takes a data frame and one optional width argument. The signature is short because the function exists to do one thing well: print a transposed summary.
The full signature is:
glimpse(x, width = NULL, ...)
xis a data frame, tibble, or any list-like object with named elements of equal length.widthis the number of characters per line. Default isgetOption("width"), usually 80 in scripts and wider in RStudio....is forwarded to method-specific implementations and is normally unused.
The return value is x itself, returned invisibly. That is what makes df |> glimpse() |> filter(...) work without printing twice.
print() shows the first 10 rows of every column; glimpse() shows every column with whatever fits in one console line. Wide data favors glimpse(); tall data favors print() or head().Examples
Each example covers a use case glimpse() handles better than the alternatives. Run them top-to-bottom in the live console; the WebR session keeps state between blocks.
1. Inspect a fresh dataset
In two lines of output you learn the row count, the column count, every column name, every column type, and the first handful of values. The NA in Ozone is immediately visible, which is harder to spot in a regular print() of the first ten rows.
2. Compare types across columns
The <dbl> and <fct> tags tell you four columns are doubles and one is a factor, without calling class() five times.
3. Inspect mid-pipeline
Because glimpse() returns its input invisibly, the chain keeps working. You see the post-filter state without rewriting the pipeline.
glimpse() to debug shape without breaking flow. It is the tidyverse equivalent of print()-debugging, and it always returns the same object it received.4. Control the line width
A narrower width truncates each row earlier, which is useful when piping output into a fixed-width log file or rendering inside a notebook with a narrow column.
glimpse() vs str(), print(), head() and summary()
Each function answers a different question about a data frame. Picking the right one saves console scrolling and decision fatigue.
| Function | Layout | Best for | Returns |
|---|---|---|---|
glimpse(df) |
One row per column, transposed | Column names + types + sample values at a glance | df invisibly |
str(df) |
Nested, attribute-aware | Internal structure of lists and complex objects | NULL invisibly |
print(df) |
Standard tabular, top N rows | Reading actual rows in tabular form | df invisibly |
head(df) |
First 6 rows tabular | Quick peek at the top of the data | First 6 rows |
summary(df) |
Per-column statistics | Distribution check (min, median, NAs) | A summary object |
Decision rule: reach for glimpse() when you want column-shaped information; reach for head() or print() when you want row-shaped information; reach for summary() when you want distributional information.
Common pitfalls
- Confusing
glimpse()output for the data itself. The visible values are truncated previews, not the full column. Usehead()orpull()if you need the actual values. - Calling
glimpse()on a non-data-frame list. It still prints, but the layout assumes equal-length elements. Convert withas_tibble()first when the structure is irregular. - Relying on
glimpse()to detect type problems. It shows the type R inferred, not the type you wanted. A column that should be numeric but contains"N/A"strings will print as<chr>without warning.
glimpse() does not signal coercion problems. If read_csv() silently parsed a date column as character because of one malformed cell, glimpse() will show <chr> and move on. Pair it with problems(df) from readr when ingesting messy data.Try it yourself
Try it: Load the built-in airquality data, convert it to a tibble, then use glimpse() to identify which two columns contain missing values and what their R types are.
Click to reveal solution
Explanation: Ozone and Solar.R show NA values in the preview, and both are typed <int> (integer). The other four columns have no visible NAs in the first few values. For a definitive count, follow up with colSums(is.na(ex_aq)).
Related tibble functions
as_tibble()to promote a basedata.frameor named list before glimpsing.print.tbl_df()for the standard tabular view of a tibble.head()andtail()for row-shaped peeks at the top and bottom.str()for attribute-aware structural inspection.View()to open an interactive spreadsheet view in RStudio.
For the full reference, see the official tibble documentation.
FAQ
What is the difference between glimpse() and str() in R?
glimpse() is optimized for data frames: it shows row count, column count, and a transposed sample of each column with a clean type tag. str() is a general-purpose inspector that walks any R object, including lists and nested attributes, and prints the underlying structure. For a data frame, glimpse() is almost always faster to read; for a fitted model or a nested list, str() is the right tool.
Does glimpse() come from dplyr or tibble?
The function lives in the tibble package and is re-exported by dplyr. Calling library(tibble) or library(dplyr) makes it available, and so does library(tidyverse). The underlying implementation is in the pillar package, which handles the column formatting for both.
Can I use glimpse() on a regular data.frame?
Yes. glimpse() works on any object that behaves like a data frame, including base R data.frame objects, data.table objects, and tibbles. It does not require conversion. The output format is identical regardless of class.
Why does glimpse() show fewer values than I expect?
glimpse() fits as many values as it can into the console width. If your terminal is narrow, you see fewer values. Pass a larger width argument, for example glimpse(df, width = 120), or widen the RStudio console pane.
Does glimpse() print the entire column or just a sample?
It prints only a sample sized to fit the line. The function never scrolls past one line per column, so very long character columns appear truncated. Use pull(df, column) or df$column when you need the full vector.