Learn R Programming

⚠️There's a newer version (0.3.0) of this package.Take me there.

docxtools

Overview

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

Installation

From CRAN,

install.packages("docxtools")

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

install.packages("devtools")
devtools::install_github("graphdr/docxtools")

Usage

The density data set is part of the package.

library(docxtools)
data("density")
density
#>         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.

knitr::kable(y, align = "ccrrrr")

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.

For put_axes() with knitr and R markdown, the axis height is specified in the R code-chunk header.

Copy Link

Version

Install

install.packages('docxtools')

Monthly Downloads

136

Version

0.2.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Richard Layton

Last Published

June 3rd, 2020

Functions in docxtools (0.2.2)

put_axes

Insert a two-dimensional coordinate axes in a document.
format_engr

Format numerical variables in engineering notation.
align_pander

Deprecated functions in package docxtools
docxtools

docxtools: R Markdown to docx helper functions.
align_pander-deprecated

align_pander
put_gap

Insert a gap or whitespace in a document.
density

Ideal gas sample data frame