bench icon indicating copy to clipboard operation
bench copied to clipboard

bench result can't be formatted as paged table in a rmarkdown document

Open cderv opened this issue 4 years ago • 1 comments

Currently this example won't output as one would expect with a tibble

---
title: "test"
output: 
  html_document:
    df_print: paged
---

```{r}
n <- 10L
output <- bench::mark(
   sort(sample.int(n), method = 'radix'),
   sort(sample.int(n), method = 'quick'),
   sort(sample.int(n), method = 'shell')
)
output
```

```{r}
tibble::as_tibble(output)
```

rmarkdown includes a paged table feature for html document to format data.frame. It will be activated in rmarkdown:::knit_print.data.frame. Issue is that this method is currently never called with the current knit_print.bench_mark

library(rmarkdown)
#> Warning: le package 'rmarkdown' a été compilé avec la version R 4.0.3
library(bench)
library(knitr)

n <- 10L
output <- bench::mark(
  sort(sample.int(n), method = 'radix'),
  sort(sample.int(n), method = 'quick'),
  sort(sample.int(n), method = 'shell')
)
output
#> # A tibble: 3 x 6
#>   expression                               min median `itr/sec` mem_alloc
#>   <bch:expr>                            <bch:> <bch:>     <dbl> <bch:byt>
#> 1 sort(sample.int(n), method = "radix") 33.7us   38us    25156.   28.25KB
#> 2 sort(sample.int(n), method = "quick") 21.6us 23.7us    38883.    2.49KB
#> 3 sort(sample.int(n), method = "shell") 21.8us 23.3us    40685.    2.49KB
#> # ... with 1 more variable: `gc/sec` <dbl>

sloop::s3_dispatch(knit_print(output))
#> => knit_print.bench_mark
#>    knit_print.tbl_df
#>    knit_print.tbl
#>  * knit_print.data.frame
#>  * knit_print.default

I believe bench should called NextMethod() instead of using print()

cderv avatar Nov 03 '20 11:11 cderv

but that is one piece of the issue only. The other one is that the expression column does not print correctly currently... image

That means html_notebook and bench does not play well...

I believe we don't have full support yet for vctrs, tibble, pillar. Some stuff must be changed in rmarkdown maybe 🤔

cderv avatar Nov 03 '20 11:11 cderv