knitr::opts_chunk$set( echo = TRUE, # varies from one Rmd to another message = FALSE, warning = FALSE, collapse = TRUE, comment = "#>", error = TRUE, purl = FALSE, fig.width = 6, fig.asp = 1 / 1.6, out.width = "70%", fig.align = "center", fig.path = "man/figures/README-" ) knitr::knit_hooks$set(inline = function(x) { if (!is.numeric(x)) { x } else if (x >= 10000) { prettyNum(round(x, 2), big.mark = ",") } else { prettyNum(round(x, 2)) } }) options(tibble.print_min = 8L, tibble.print_max = 8L)
docxtools is a small set of helper functions for using R Markdown to create documents in docx format, especially documents for use in a classroom or workshop setting. These are particularly useful when one tries to do one's own work reproducibly but has collaborators who work with Office software exclusively.
format_engr()
to apply engineering format to numbers put_gap()
to create white space in a document put_axes()
to place unlabeled axes in a document From CRAN,
install.packages("docxtools")
Or you can obtain the most recent development version from GitHub.
install.packages("remotes") remotes::install_github("graphdr/docxtools")
The density
data set is part of the package.
library(docxtools) data("density") density
format_engr()
applies engineering notation to numeric variables, assigns significant digits, and adjusts for ambiguous trailing zeros.
y <- format_engr(density, sigdig = c(5, 4, 0, 4), ambig_0_adj = TRUE)
For printing the table, I suggest using knitr::kable()
. (Note: The table can be seen correctly rendered at the package website.) docxtools < 0.1.4 used the align_pander()
function that is now deprecated and soon to be defunct.
knitr::kable(y, align = "ccrrrr")
# latex, html, markdown, pandoc, and rst; knitr::kable(y, align = "ccrrrr", format = "html")
Using put_gap()
with knitr and R markdown, the gap height is specified in the R code-chunk header.
```r
# a gap with a border
put_gap(col = "gray", fill = NULL)
```
# a gap with a border put_gap(col = "gray", fill = NULL)
For put_axes()
with knitr and R markdown, the axis height is specified in the R code-chunk header.
```r
# first quadrant axes
put_axes(1, col = "blue", linewidth = 0.5)
```
# first quadrant axes put_axes(1, col = "blue", linewidth = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.