glimpse( )
Inspect a data object by showing columns, data types, and example values. glimpse() is re-exported by dplyr and available through the tidyverse.
Required Library
install.packages("tidyverse")
library(tidyverse)Syntax
# Pipe style
df %>% glimpse()
# Non-pipe style
glimpse(df)df %>% glimpse() and glimpse(df) print a compact overview of the object. For tibbles and data frames, the output shows the number of rows and columns, each column name, its data type, and example values.
glimpse(df, width = 60)Use width = when you want to control how much horizontal space the printed output uses. Smaller widths wrap sooner; larger widths can show more values on one line.
glimpse() instead of View() or print()?
glimpse() gives you a quick look at your data: column names, types, and the first few values, all in one view. Unlike print(), it won’t cut off columns when your dataframe is wide. Unlike View(), it shows up right in your script, so you don’t need to open a separate window. It also doesn’t change your data — it just shows it to you and passes it along, so you can use it inside a pipe without breaking your workflow.
Examples
Inspect a tibble after importing it
Use glimpse() inside a pipe
Because glimpse() returns the original data invisibly, you can inspect the data and continue the pipeline.
Control how much output is shown with width
By default, glimpse() uses the full width of your console. Set width to limit how many characters are printed per line, which is useful for narrower windows or when sharing output.
Argument Overview
Required arguments must be included when using a function while optional arguments can be included on demand.
x — object to inspect data frame | tibble | other R object Required
The object to inspect. glimpse() is most commonly used with tibbles and data frames, but it can also inspect other R objects.
glimpse(tablet_weights)
Data Types: usually tibble or data.frame, but other object types are also accepted
width — output width numeric Optional
Controls how wide the printed output can be. If omitted, glimpse() uses the current console width.
glimpse(tablet_weights, width = 60)
Data Types: numeric · Default: NULL (use console width)
… — unused extra arguments various Optional
Reserved for extensibility. Most users can ignore this and call glimpse(x) with no extra arguments.
Data Types: not typically used in beginner workflows