Overriding "Variables not shown" in dplyr, to display all columns from df Overriding "Variables not shown" in dplyr, to display all columns from df r r

Overriding "Variables not shown" in dplyr, to display all columns from df


There's (now) a way of overriding the width of columns that gets printed out. If you run this command all will be well

options(dplyr.width = Inf)

I wrote it up here.


You might like glimpse :

> movies %>%+  group_by(year) %>%+  summarise(Length = mean(length), Title = max(title),+   Dramaz = sum(Drama), Actionz = sum(Action),+   Action = sum(Action), Comedyz = sum(Comedy)) %>%+  mutate(Year1 = year + 1) %>% glimpse()Variables:$ year    (int) 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902,...$ Length  (dbl) 1.000000, 1.000000, 1.000000, 1.307692, 1.000000, 1.000000,...$ Title   (chr) "Blacksmith Scene", "Sioux Ghost Dance", "Photographe", "Ve...$ Dramaz  (int) 0, 0, 0, 1, 0, 1, 2, 2, 5, 1, 2, 3, 4, 5, 1, 8, 14, 14, 14,...$ Actionz (int) 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 0, 3, 0, 0, 1, 0,...$ Action  (int) 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 0, 0, 0, 0, 3, 0, 0, 1, 0,...$ Comedyz (int) 0, 0, 0, 1, 2, 2, 1, 5, 8, 2, 8, 10, 6, 2, 6, 8, 7, 2, 2, 4...$ Year1   (dbl) 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903,...NULL


dplyr has its own printing functions for dplyr objects. In this case, the object that is the result of your operation is tbl_df. The matching print function is then dplyr:::print.tbl_df. This reveals that trunc_mat is the function responsible for what is printed and not, including which variables.

Sadly, dplyr:::print.tbl_df does not pass on any parameters to trunc_mat and trunc_mat also does not support choosing which variables are shown (only how many rows). A workaround is to cast the result of dplyr to a data.frame and use head:

res = movies %.%  group_by(year) %.%  summarise(Length = mean(length), Title = max(title),   Dramaz = sum(Drama), Actionz = sum(Action),   Action = sum(Action), Comedyz = sum(Comedy)) %.%  mutate(Year1 = year + 1)head(data.frame(res))  year    Length                       Title Dramaz Actionz Action Comedyz1 1898  1.000000 Pack Train at Chilkoot Pass      1       0      0       22 1894  1.000000           Sioux Ghost Dance      0       0      0       03 1902  3.555556     Voyage dans la lune, Le      1       0      0       24 1893  1.000000            Blacksmith Scene      0       0      0       05 1912 24.382353            Unseen Enemy, An     22       0      0       46 1922 74.192308      Trapped by the Mormons     20       0      0      16  Year11  18992  18953  19034  18945  19136  1923