Is there a way to customise the knitr::kable() output for Jira style tables?

Azhar Ali July 12, 2021

I am trying to create a table output formatting that matches the style of Jira tables. Jira uses pipes like in the knitr::kable(format = "pipe") output but differs with regards to the column headers. Here is an example of my current table format using the knitr package:

data("BOD")
BOD %>% tibble::tibble() %>% 
  head(n = 10) %>% 
  knitr::kable(format = "pipe")

> | Time| demand|
  |----:|------:|
  |    1|    8.3|
  |    2|   10.3|
  |    3|   19.0|
  |    4|   16.0|
  |    5|   15.6|
  |    7|   19.8|

Instead of using a line to separate the headers from the column content, Jira has a slightly different switch syntax:

|| Time|| demand||
|     1|     8.3|
|     2|    10.3|
|     3|    19.0|
|     4|    16.0|
|     5|    15.6|
|     7|    19.8|

Currently, I am removing the ›separation row‹ and modifying the first row:

BOD %>% tibble::tibble() %>% 
  head(n = 10) %>% 
  knitr::kable(format = "pipe") -> tmp
tmp <- tmp[-2] 
tmp[1] <- stringr::str_replace_all(tmp[1], pattern = "\\|", replacement = "||")
tmp %>% writeClipboard() # Paste into Jira
# Output:
|| Time|| demand||
|    1|    8.3|
|    2|   10.3|
|    3|   19.0|
|    4|   16.0|
|    5|   15.6|
|    7|   19.8|

Is there a way to customise the kable() output in order to achieve Jira compatibility?

0 answers

Suggest an answer

Log in or Sign up to answer