officedown

repository·main·Indexed 18 days ago

https://github.com/davidgohel/officedown

An R package that extends R Markdown to produce highly formatted Microsoft Word and PowerPoint documents. It bridges R Markdown with the officer package to enable advanced styling, template-based layouts via reference_docx, and smart cross-referencing using Word bookmarks. Key features include full flextable support with images in cells for Word output and the creation of editable vector graphics in PowerPoint using the dml function and rvg package.

Tokens
1.4K
Snippets
5
Records
11
Agent score
13%

What's inside officedown

  1. Enhance PowerPoint output with officedown

    main

    The package improves R Markdown to PowerPoint conversion by:

    • Template alignment: Placing results according to the slide template defined in your reference_doc.
    • Multi-content slides: Making it easier to add multiple content elements to a single slide.
    • Editable vector graphics: You can wrap graphic instructions in the dml() function to transform them into editable vector graphics using the rvg package.
  2. Use rdocx_document for Word output

    main

    To produce enhanced Microsoft Word documents, set the output format in your R Markdown YAML header to officedown::rdocx_document. This enables advanced features like:

    • officer compatibility: Use functions from the officer package to create "runs" and "blocks" (e.g., text formatting, landscape mode, column breaks, and colored text).
    • Style reuse: Use a reference_docx template to reuse Word paragraph, table, and list styles.
    • Smart cross-referencing: Automatically replaces bookdown-style cross-references and captions with Word bookmarks and fields. This allows for auto-numbering and easy copy-pasting without losing reference integrity.
    • Flextable support: Full support for flextable outputs, including the ability to include images or plots within cells (which standard rmarkdown::word_document does not support).
    output: officedown::rdocx_document
    reference_docx: path/to/your/template.docx
  3. Overview of officedown

    main
    The {officedown} package extends R Markdown capabilities to produce enhanced Microsoft Word and PowerPoint documents. It integrates features from the {officer} package, allowing for advanced formatting, style reuse, and improved cross-referencing within R Markdown workflows.
  4. Enhance Word document formatting with officedown

    main

    When producing Microsoft Word documents via R Markdown, {officedown} provides several advanced formatting capabilities:

    • Officer Integration: Use {officer} functions to create 'runs' and 'blocks' of content (e.g., text formatting, landscape mode, tables of contents).
    • Advanced Layout: Add column breaks in two-column sections, color text chunks, and insert tables of contents, lists of figures, or lists of tables at any location.
    • Style Reuse: Use a reference_docx template to reuse Word paragraph, table, and list styles defined in a custom Word document.
    • Smart Cross-referencing: Replaces standard captions and identifiers with Word bookmarks and fields. This allows for auto-numbering by Word and ensures reference numbers are preserved when copying content into other documents. It supports bookdown cross-reference syntax for tables, images, and titles.
    • Flextable Support: Enables full support for flextable output, including the ability to include images or plots within cells (which is not supported by standard rmarkdown::word_document).
  5. Enhance PowerPoint production with officedown

    main

    For Microsoft PowerPoint output, {officedown} provides:

    • Template Alignment: Places results according to the slide template defined in a reference_doc, making it easier to add multiple content elements to a single slide.
    • Editable Vector Graphics: Transform graphic instructions into editable vector graphics by wrapping calls in the dml function (requires the rvg package).
  6. Create a new officedown document

    main

    To start a new project, use the RStudio Menu to create a document from the {officedown} template. This automatically configures the R Markdown file with the correct output format.

    Key Configuration:

    • The output parameter in the YAML header is set to officedown::rdocx_document.
    • Important: You must explicitly load the {officedown} package within your R Markdown file (e.g., using library(officedown) in a setup chunk) for the features to work.
    output: officedown::rdocx_document
  7. Install officedown from GitHub

    main

    You can install the development version of {officedown} using the remotes package.

    Prerequisites: Ensure you have a compatible version of Pandoc installed:

    • For Microsoft Word: Pandoc >= 2.0
    • For Microsoft PowerPoint: Pandoc >= 2.4
    remotes::install_github("davidgohel/officedown")
  8. Run the officedown bookdown demo

    main

    You can explore the capabilities of {officedown} by running the included bookdown example. This copies the example directory to your working directory and renders it.

    dir <- system.file(package = "officedown", "examples", "bookdown")
    file.copy(dir, getwd(), recursive = TRUE, overwrite = TRUE)
    # rmarkdown::render_site("bookdown")
  9. Use rdocx_document as the output format

    main
    To use {officedown} features for Word output, set the R Markdown output type to officedown::rdocx_document. This is required to enable advanced features like flextable with images and specialized Word formatting that standard rmarkdown::word_document does not support.