0
library(dplyr)
df <- as.data.frame(matrix(0, ncol = 200, nrow = 1))
names(df) <- paste0('col', 1:200)
df %>% as_tibble()
# A tibble: 1 x 200
#>    col1  col2  col3  col4  col5  col6  col7  col8  col9 col10 col11 col12
#>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1     0     0     0     0     0     0     0     0     0     0     0     0
#> # ... with 188 more variables: col13 <dbl>, col14 <dbl>, col15 <dbl>,
#> #   col16 <dbl>, col17 <dbl>, col18 <dbl>, col19 <dbl>, col20 <dbl>,
#> #   col21 <dbl>, col22 <dbl>, col23 <dbl>, col24 <dbl>, col25 <dbl>,
#> #   col26 <dbl>, col27 <dbl>, col28 <dbl>, col29 <dbl>, col30 <dbl>,
#> #   col31 <dbl>, col32 <dbl>, col33 <dbl>, col34 <dbl>, col35 <dbl>,
#> #   col36 <dbl>, col37 <dbl>, col38 <dbl>, col39 <dbl>, col40 <dbl>,
#> #   col41 <dbl>, col42 <dbl>, col43 <dbl>, col44 <dbl>, col45 <dbl>,
#> #   col46 <dbl>, col47 <dbl>, col48 <dbl>, col49 <dbl>, col50 <dbl>,
#> #   col51 <dbl>, col52 <dbl>, col53 <dbl>, col54 <dbl>, col55 <dbl>,
#> #   col56 <dbl>, col57 <dbl>, col58 <dbl>, col59 <dbl>, col60 <dbl>,
#> #   col61 <dbl>, col62 <dbl>, col63 <dbl>, col64 <dbl>, col65 <dbl>,
#> #   col66 <dbl>, col67 <dbl>, col68 <dbl>, col69 <dbl>, col70 <dbl>,
#> #   col71 <dbl>, col72 <dbl>, col73 <dbl>, col74 <dbl>, col75 <dbl>,
#> #   col76 <dbl>, col77 <dbl>, col78 <dbl>, col79 <dbl>, col80 <dbl>,
#> #   col81 <dbl>, col82 <dbl>, col83 <dbl>, col84 <dbl>, col85 <dbl>,
#> #   col86 <dbl>, col87 <dbl>, col88 <dbl>, col89 <dbl>, col90 <dbl>,
#> #   col91 <dbl>, col92 <dbl>, col93 <dbl>, col94 <dbl>, col95 <dbl>,
#> #   col96 <dbl>, col97 <dbl>, col98 <dbl>, col99 <dbl>, col100 <dbl>,
#> #   col101 <dbl>, col102 <dbl>, col103 <dbl>, col104 <dbl>, col105 <dbl>,
#> #   col106 <dbl>, col107 <dbl>, col108 <dbl>, col109 <dbl>, col110 <dbl>,
#> #   col111 <dbl>, col112 <dbl>, ...

My 200 column tibble above only displays 112 columns in my R console. How do I display all columns without truncation?

This doesn't work:

?as_tibble()
df %>% as_tibble(.rows = 200)
df %>% as_tibble(n = 200)

instead of the trailing ... in the first code block I want to see all columns, including columns after col112.

Display name
  • 4,153
  • 5
  • 27
  • 75
  • 5
    `options(dplyr.width = Inf)` – Ronak Shah Dec 12 '19 at 01:47
  • @Ronak Shah Thanks for `df %>% as_tibble(options(dplyr.width = Inf))`. That works but I don't really need the single value for each column. Would prefer to keep the same `as_tibble()` output format. Do you know how? – Display name Dec 12 '19 at 01:50
  • [This post](https://stackoverflow.com/questions/46994722/displaying-all-the-rows-and-columns-of-tibble-in-r-markdown) also suggests `options(tibble.width)` as an alternative. – thelatemail Dec 12 '19 at 01:51
  • 1
    @thelatemail I think we both misunderstood the question. In the output of `df %>% as_tibble()`, you see `with 188 more variables: col13 col14 ,.....` it ends at `col111 , col112 .` OP wants it to be till `col199 , col200 `. meaning print all the columns. (Hopefully, I have got it this time). – Ronak Shah Dec 12 '19 at 01:54
  • Yes, Ronak has correctly described my intent. Sorry that that was not clear. – Display name Dec 12 '19 at 01:55
  • 1
    @RonakShah - ah, I see. Why not just use `colnames(df)` then if the values aren't required? – thelatemail Dec 12 '19 at 01:55
  • 1
    `options(...)` returns the *previous* values for the specified option(s), so even if `as_tibble` takes `dplyr.width=` as an argument (it does not), it would not get the desired/new value. Perhaps `options(dplyr.width=300)` (or slightly higher) to get what you need. Not `Inf`. Nor will `nrows=` change the number of columns printed. I tried `options(dplyr.width=300)` and see 152 cols; 400 for 165 cols; it took 561 to see all 200 columns. – r2evans Dec 12 '19 at 01:59
  • @thelatemail Thanks for that suggestion but I'm more curious how to do it utilizing the `as_tibble()` function. Maybe it simply isn't an argument in the function, or possible, in which case I'll settle for `colnames()` or `str()`. – Display name Dec 12 '19 at 01:59
  • @r2evans so I guess I can't really use `options(dplyr.width = nrows(df))` unless I do something silly like `options(dplyr.width = nrows(df) ^ 2)`? – Display name Dec 12 '19 at 02:02
  • 1
    `width` and `nrows` are different things. But no, you can't do `options(dplyr.width=ncol(df))` either. You can do `as_tibble(df) %>% print(width=562)` or so (see `?options`). – r2evans Dec 12 '19 at 02:10

1 Answers1

5

There is n_extra parameter in print method which will help you achieve this.

print(df %>% as_tibble(), n_extra = 200)

# A tibble: 1 x 200
#   col1  col2  col3  col4  col5  col6  col7  col8  col9 col10 col11 col12
#  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#1     0     0     0     0     0     0     0     0     0     0     0     0
# … with 188 more variables: col13 <dbl>, col14 <dbl>, col15 <dbl>,.....
#.......................................................................
#   .......col196 <dbl>, col197 <dbl>, col198 <dbl>, col199 <dbl>, col200 <dbl>
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213