Skip to content

Instantly share code, notes, and snippets.

@vm-wylbur
Created January 1, 2019 02:09
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vm-wylbur/b98d540adce9d874bdef63344b335f74 to your computer and use it in GitHub Desktop.
use non-breaking thin space as thousands separator in rmarkdown
myNum <- function(n) {
# use in markdown with variable some_number:
# `r myNum(some_number)` and the thousands separator is a
# nonbreaking thin space, which is ISO 30-1
return(prettyNum(n, big.mark='&thinsp;'))
}
@vm-wylbur
Copy link
Author

Don't use commas or periods as thousands separator. Use the thin space.

@thegargiulian
Copy link

I've found that this function doesn't work (or no longer works) when inside kable tables when knitting to pdf. You have to use the unicode character instead of '&thinsp;':

myNum <- function(n) {
  # use in markdown with variable some_number:
  # `r myNum(some_number)` and the thousands separator is a
  # nonbreaking thin space, which is ISO 30-1
  return(prettyNum(n, big.mark = "\U2009"))
}

@vm-wylbur
Copy link
Author

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment