elipousson / officerExtras

🏢 A R package with {officer} helper functions.
https://elipousson.github.io/officerExtras/
Other
13 stars 0 forks source link
microsoft-word officer r-package rstats

officerExtras officerExtras website

Lifecycle:
experimental License:
MIT Project Status: WIP – Initial development is in progress, but there
has not yet been a stable, usable release suitable for the
public. Codecov test
coverage

The goal of officerExtras is to provide helper and convenience functions for the {officer} package.

Installation

You can install the development version of officerExtras like so:

pak::pkg_install("elipousson/officerExtras")

Usage

The officerExtras package provides a variety of helper functions to simplify the process of working with officer. For example, a single read_officer() function works with docx, pptx, or xlsx files:

library(officerExtras)

docx <- read_officer(filename = "example.docx", path = system.file("doc_examples", package = "officer"))

pptx <- read_officer(filename = "example.pptx", path = system.file("doc_examples", package = "officer"))

officer uses a print method to save rdocx, rpptx, or rxlsx objects back to files. officerExtras provides a write_officer() with that adds the option to pass a filename and path separately and pass document properties to officer::doc_properties().

withr::with_tempdir({
  write_officer(docx, "write-example.docx", modified_by = "officerExtras", title = "Document Title set by doc_properties", subject = "Microsoft Word, R")

  example_docx <- read_officer("write-example.docx")

  officer::doc_properties(example_docx)
})
#>               tag                                value
#> 1           title Document Title set by doc_properties
#> 2         subject                    Microsoft Word, R
#> 3         creator                               author
#> 4        keywords                                     
#> 5     description                   these are comments
#> 6  lastModifiedBy                        officerExtras
#> 7        revision                                   12
#> 8         created                 2017-04-26T13:10:00Z
#> 9        modified                 2023-06-22T11:04:39Z
#> 10       category

The package also wraps useful functions from a few other packages. convert_docx() uses rmarkdown::pandoc_convert() to convert a rdocx object or a Word document to any other pandoc supported output format:

convert_docx(docx, to = "markdown")

Related projects

There are a number of related projects for extending officer or working with OOXML in R and other languages.

Extending officer

Working with Microsoft Office documents with R

Other tools for working with Microsoft Office documents