tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.
https://reprex.tidyverse.org
Other
741 stars 80 forks source link

Reprex v2.0.2 does not print all columns of bench::mark() #436

Closed DesiQuintans closed 11 months ago

DesiQuintans commented 1 year ago

bench::mark() produces a summary tibble with 13 columns, but Reprex only shows the first 6 of them (see first run of mark() in reprex below). It does this even if you select all columns by index or name. The columns really are there (see second run of mark()), it's just that reprex won't print them. It doesn't print any column above 6 even if you specifically select them with mark(...)[, c(1, 7)] (see third run of mark()).

library(bench)
library(dplyr)

mark(
    expr_1 = length(rep(month.name, 1e6)),
    expr_2 = length(rep(month.abb, 1e6))
)

#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 expr_1       51.1ms   57.1ms      16.9    91.6MB     16.9
#> 2 expr_2       55.1ms   56.9ms      17.5    91.6MB     17.5

mark(
    expr_1 = length(rep(month.name, 1e6)),
    expr_2 = length(rep(month.abb, 1e6))
) %>% glimpse()

#> Rows: 2
#> Columns: 13
#> $ expression <bch:expr> <length(rep(month.name, 1e+06))>, <length(rep(month.ab…
#> $ min        <bch:tm> 51.3ms, 55.3ms
#> $ median     <bch:tm> 56.4ms, 58ms
#> $ `itr/sec`  <dbl> 17.52124, 17.01236
#> $ mem_alloc  <bch:byt> 91.6MB, 91.6MB
#> $ `gc/sec`   <dbl> 17.52124, 17.01236
#> $ n_itr      <int> 9, 9
#> $ n_gc       <dbl> 9, 9
#> $ total_time <bch:tm> 514ms, 529ms
#> $ result     <list> 12000000, 12000000
#> $ memory     <list> [<Rprofmem[1 x 3]>], [<Rprofmem[1 x 3]>]
#> $ time       <list> <56.4ms, 56.4ms, 51.3ms, 53.5ms, 53.9ms, 72.4ms, 53.4ms,…
#> $ gc         <list> [<tbl_df[9 x 3]>], [<tbl_df[9 x 3]>]

mark(
    expr_1 = length(month.name),
    expr_2 = length(month.name)
)[, c(1, 7)]

#> # A tibble: 2 × 1
#>   expression
#>   <bch:expr>
#> 1 expr_1    
#> 2 expr_2
hadley commented 11 months ago

This is a bench feature. The docs say:

' By default, data columns (result, memory, time, gc) are omitted when

' printing in knitr. If you would like to include these columns, set the knitr

' chunk option bench.all_columns = TRUE.