Skip to content
Discussion options

You must be logged in to vote

Many thanks, @rgaiacs! I wasn't familiar with knitr hooks. This solution works, however, sweeps up non-numeric variables, i.e, dates.

Based on your suggestion as well as a stackoverflow discussion on formatting all dates, I added to the top of my Quarto document:

# Format integers
knit_print.integer = function(x, ...) {
  prettyNum(x, big.mark=",")
}

registerS3method(
  "knit_print", "integer", knit_print.integer,
  envir = asNamespace("knitr")
)

# Format dates
knit_print.Date = function(x, ...) {
  format(x, "%d %B %Y")
}

registerS3method(
  "knit_print", "Date", knit_print.Date,
  envir = asNamespace("knitr")
)

This prints 1,500 and 16 August 2023.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@maia-sh
Comment options

Answer selected by maia-sh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants