4

The pillar package offers a number of options to format tibble printing.

https://pillar.r-lib.org/reference/pillar-package.html#package-options

For example, this is what I see on my Windows machine, which supports these options:

enter image description here

But when I set the same options for rmarkdown document, I don't see any difference in the printed output.

enter image description here

Is there a way to successfully get this to work or this is not supported in rmarkdown itself?

Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
  • 1
    from [pillar usage](https://github.com/r-lib/pillar) : "pillar is a developer-facing package that is not designed for end-users" – Waldi Oct 18 '20 at 06:33

2 Answers2

2

I'd say that from my markdown experience that Pillow will not work as markdown uses pandoc.

As alternatives, I'd recommend using the kable package for a similar look using it's themes options. A handy tutorial with using a relatively similar theme ->

https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html

Another cool option of making really cool markdown tables would be to use formattable, which has a lot of in-depth options for formatting

formattable example

And a couple of handy tutorials for that ->

https://www.littlemissdata.com/blog/prettytables

https://www.littlemissdata.com/blog/pretty-r-tables-in-github

Hopefully, this helps you out.

Ram Pari
  • 66
  • 5
2

In the vignette for the tibble package, there is a possible solution. In your setup chunk of your .Rmd file, put:

knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(tibble)
set.seed(1014)

options(crayon.enabled = TRUE)
options(pillar.bold = TRUE, pillar.subtle_num = TRUE)

knitr::opts_chunk$set(collapse = TRUE, comment = pillar::style_subtle("#>"))

colourise_chunk <- function(type) {
  function(x, options) {
    lines <- x
    if (type != "output") {
      lines <- crayon::red(lines)
    }
    paste0(
      '<div class="sourceCode"><pre class="sourceCode"><code class="sourceCode">',
      paste0(
        fansi::sgr_to_html(htmltools::htmlEscape(lines)),
        collapse = "\n"
      ),
      "</code></pre></div>"
    )
  }
}

knitr::knit_hooks$set(
  output = colourise_chunk("output"),
  message = colourise_chunk("message"),
  warning = colourise_chunk("warning"),
  error = colourise_chunk("error")
)

In a new chunk:


broom::tidy(stats::chisq.test(table(ggplot2::msleep$vore)))

My HTML output:

tibble output

W. Joel Schneider
  • 1,711
  • 13
  • 14