r-markdown

R Markdown Table 1000 separator


I am trying to publish a table with 1000 separators and I am not having any luck with it. I followed the link here: Set global thousand separator on knitr but am not having much success.

The RMarkdown code is here:

---
title: "Table Example"
author: "Krishnan Viswanathan"
date: "August 4, 2015"
output: html_document
---

Load Data

load("i75_from_flow.RData")
library(data.table)
i75_from_flow <- i75_from_flow[order(-Tons),]
knitr::kable(i75_from_flow)

However, when I include this chunk of code (knit_hook$set) in the RMarkdown document, i get errors.

```{r, results='asis', echo=FALSE,message = FALSE, tidy=TRUE}
i75_from_flow <- i75_from_flow[order(-Tons),]
knit_hooks$set(inline = function(x) {
prettyNum(x, big.mark=",")
})
knitr::kable(i75_from_flow)
```

Error:

# object knit_hooks not found.

Solution

  • What about using pander with bunch of options to fine-tune your markdown table:

    > pander::pander(i75_from_flow, big.mark = ',')
    
    ----------------------------
     ORIGFIPS   TERMFIPS   Tons 
    ---------- ---------- ------
      12,023     12,117   5,891 
    
      12,119     12,105   4,959 
    
      12,001     12,057   3,585 
    
      12,001     12,113   3,083 
    
      12,047     12,047   1,517 
    ----------------------------