Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is the result of glimpse() a tibble for some but not all data?

So I’m running some code on a dataset that is 9992 rows and 10 columns. Specifically, I’m checking if the dataset’s glimpse is a tibble, i.e., data %>% glimpse() %>% is_tibble(). It is outputting TRUE. But on other datasets, like the cars dataset, I’m getting FALSE. Why might this be the case?

I ran data %>% glimpse() %>% is_tibble() and cars %>% glimpse() %>% is_tibble()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

glimpse just prints the data in a transposed way and it does nothing on the data. The is_tibble will return TRUE only if the underlying data is tibble. Here, cars is not

> class(cars)
[1] "data.frame"

If we convert to tibble, it will show TRUE for is_tibble

> cars %>% 
  as_tibble %>% 
  glimpse() %>% 
  is_tibble()
Rows: 50
Columns: 2
$ speed <dbl> 4, 4, 7, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17,…
$ dist  <dbl> 2, 10, 4, 22, 16, 10, 18, 26, 34, 17, 28, 14, 20, 24, 28, 26, 34, 34, 46, 26, 36, 60, 80, 20, 26, 54, 32, 40, 32,…
[1] TRUE
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading