Here is an example that illustrates two ways to print large quantities in an R Markdown document. Firstly, the code for using the prettyNum() function in the built-in part of R.
Sample document where we test printing a large number. First set the number in an R chunk. ```{r initializeData} theNum <- 1234567891011.03 options(scipen=999,digits=16) ``` The R code we'll use to format the number is: `prettyNum(theNum,width=23,big.mark=",")`. Next, print the large number. `r prettyNum(theNum,width=23,big.mark=",")`.
An alternative to using chunk options is as follows.
Now, try an alternative using knitr chunks. ```{r prettyNumHook } knitr::knit_hooks$set(inline = function(x) { if(!is.numeric(x)){ x }else{ prettyNum(x, big.mark=",",width=23) } }) ``` Next, print the large number by simply referencing the number in an inline chunk as `theNum`: `r theNum`.
When both pieces of code are embedded in the Rmd file and knit, the output is as follows, showing that both technologies give the same result.

Yours faithfully,
Len
source share