Tools for R Markdown to Docx Documents

A set of helper functions for using R Markdown to create documents in docx format, especially documents for use in a classroom or workshop setting.

CRAN_Status_Badge BuildStatus CoverageStatus License:MIT


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,


Or you can obtain the most recent development version from GitHub.



The density data set is part of the package.

#>         date trial    T_K   p_Pa   R  density
#> 1 2018-06-12     a 294.05 101100 287 1.197976
#> 2 2018-06-13     b 294.15 101000 287 1.196384
#> 3 2018-06-14     c 294.65 101100 287 1.195536
#> 4 2018-06-15     d 293.35 101000 287 1.199647
#> 5 2018-06-16     e 293.85 101100 287 1.198791

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.

# align_pander(y) # deprecated
date trial T_K p_Pa R density
2018-06-12 a (294.05) ({101.1}\times 10^{3}) (287) (1.198)
2018-06-13 b (294.15) ({101.0}\times 10^{3}) (287) (1.196)
2018-06-14 c (294.65) ({101.1}\times 10^{3}) (287) (1.196)
2018-06-15 d (293.35) ({101.0}\times 10^{3}) (287) (1.200)
2018-06-16 e (293.85) ({101.1}\times 10^{3}) (287) (1.199)

Using put_gap() with knitr and R markdown, the gap height is specified in the R code-chunk header.

```{r fig.height = 0.75}
# 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 fig.height = 2}
# first quadrant axes
put_axes(1, col = "blue", size = 0.5)


docxtools 0.2.1 (2019-02-09)

  • Edited vignette to accommodate deprecated function align_pander(). Help pages for deprecated functions are available by running help("docxtools-deprecated").

  • Edited function n() as dplyr::n() for compatibility with dplyr release 0.8.0

docxtools 0.2.0 (2018-07-05)

This update removes the dependency on CRAN package pander, now scheduled for archival on 2018--07--19.


  • align_pander() deprecated, suggest using knitr::kable() instead

Minor improvements

  • Switched pipe dependency from magrittr to dplyr

docxtools 0.1.3 (2018-06-19)

  • Updated unit testing for compatibility with latest version of ggplot2

docxtools 0.1.2 (2018-06-14)

Bug fixes

In format_engr()

  • Corrected an error caused by an incorrect use of str_trunc().
  • Variable types date, factor, ordered factor, and character are now correctly ignored by the formatting routine.

New features

In format_engr(), added the ambig_0_adj argument. An optional argument to reformat (or not) to address ambiguous trailing zeros.

Minor improvements

For format_engr()

  • Replaced the formatting using sprintf() with formatC() for better control of significant trailing zeros.
  • Require the input to be a data frame.
  • Require the significant digits vector to have length 1 or match the number of numeric variables.
  • Replaced some code with tidy evaluation.
  • Revised the vignettes and examples.
  • Unit testing to provide 100% coverage.

docxtools 0.1.1 (2017-03-10)

  • released to CRAN

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.2.2 by Richard Layton, a year ago

Report a bug at

Browse source code at

Authors: Richard Layton [aut, cre]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports dplyr, ggplot2, lubridate, purrr, rlang, stringr, tidyr

Suggests covr, knitr, rmarkdown, rprojroot, testthat

See at CRAN