### Access PowerPoint Example Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Locates the path to a minimal PowerPoint example Rmd file within the installed officedown package. ```r # PowerPoint example system.file(package = "officedown", "examples/minimal_powerpoint.Rmd") ``` -------------------------------- ### Access Bookdown Example Directory Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Locates the path to the Bookdown example directory within the installed officedown package. ```r # Bookdown example system.file(package = "officedown", "examples/bookdown") ``` -------------------------------- ### Copy and Render officedown Example Bookdown Source: https://github.com/davidgohel/officedown/blob/main/README.md Copies an example bookdown project from the installed officedown package to the current working directory and demonstrates how to list its file structure. This is useful for exploring the package's capabilities. ```r dir <- system.file(package = "officedown", "examples", "bookdown") file.copy(dir, getwd(), recursive = TRUE, overwrite = TRUE) #> [1] TRUE # rmarkdown::render_site("bookdown") fs::dir_tree("bookdown", recurse = TRUE) #> bookdown #> ├── 01-intro.Rmd #> ├── 02-toc.Rmd #> ├── 03-tables.Rmd #> ├── 04-sections.Rmd #> ├── 05-plots.Rmd #> ├── _bookdown.yml #> ├── _output.yml #> ├── bookdown.Rproj #> ├── index.Rmd #> └── template.docx ``` -------------------------------- ### Configuration Guide Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/_COMPLETION_REPORT.txt Documentation for all parameters and options available in the officedown package. This guide helps users understand how to customize document generation, including table styling, plot styling, list styling, and page setup. ```APIDOC ## Configuration Guide Documentation for all parameters and options available in the officedown package. This guide helps users understand how to customize document generation, including table styling, plot styling, list styling, and page setup. ``` -------------------------------- ### Access Word Document Example Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Locates the path to a minimal Word document example Rmd file within the installed officedown package. ```r # Word document example system.file(package = "officedown", "examples/minimal_word.Rmd") ``` -------------------------------- ### Install officedown Package Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Install the officedown package from CRAN. This is the first step before using the package. ```r install.packages("officedown") ``` -------------------------------- ### Install officedown Package Source: https://github.com/davidgohel/officedown/blob/main/README.md Install the officedown package from GitHub using the remotes package. Ensure you have the necessary R packages and build tools installed. ```r remotes::install_github("davidgohel/officedown") ``` -------------------------------- ### Configure Word Document Page Setup Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Configure page size and margins for a Word document using rdocx_document. This is useful for setting up specific document layouts. ```r rdocx_document( page_size = list(width = 8.5, height = 11, orient = "portrait"), page_margins = list( top = 1, bottom = 1, left = 1.25, right = 1.25, header = 0.5, footer = 0.5 ) ) ``` -------------------------------- ### Bookdown Cross-Reference Syntax Examples Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Provides examples of Bookdown's reference syntax for tables, figures, and headings. This syntax is used to create dynamic links within documents. ```markdown \@ref(tab:mytable) # References table with id "mytable" \@ref(fig:myplot) # References figure with id "myplot" \@ref(section) # References heading with id "section" ``` -------------------------------- ### Create Markdown Bookmark Wrapper Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Creates a markdown string with bookmark start and end tags for OOXML. Generates a unique UUID for each bookmark and wraps the provided content. ```r as_bookmark_md(id, str) ``` -------------------------------- ### Block Landscape Macro Configuration Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Example of embedding YAML configuration within comments for block macros. Specifies width and height for landscape blocks. ```markdown Content ``` -------------------------------- ### Specify Word Template Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use the 'reference_docx' argument to provide a custom Word template (.docx file). This template defines table styles, list numbering, paragraph styles, character styles, and page setup. ```R rdocx_document(..., reference_docx = "path/to/template.docx") ``` -------------------------------- ### Render R Markdown to PowerPoint with Custom Template Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rpptx_document.md Render an R Markdown file ('presentation.Rmd') to a PowerPoint presentation ('presentation.pptx') using a custom template ('my_template.pptx'). Ensure pandoc version 2.4 or higher is installed. ```r library(rmarkdown) library(officedown) render( "presentation.Rmd", output_format = rpptx_document( reference_doc = "my_template.pptx" ), output_file = "presentation.pptx" ) ``` -------------------------------- ### Markdown with Numbered Section References Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/caption_and_references.md Example of markdown input for post_knit_std_references when numbered = TRUE. The output will be a Word field displaying the section number. ```markdown See \@ref(methods) for details. ``` -------------------------------- ### rpptx_document with Options YAML Configuration Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Configure advanced options for PowerPoint presentation generation, including a reference template, default layout, and master layout. ```yaml --- title: "My Presentation" output: officedown::rpptx_document: reference_doc: "template.pptx" layout: "Title and Content" master: "Office Theme" --- ``` -------------------------------- ### Get Style ID Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Retrieves the unique identifier (ID) for a given style name and type from the styles information. This is an internal function. ```r style_id(x, type, si) ``` -------------------------------- ### Basic rpptx_document Rendering Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rpptx_document.md Renders an R Markdown file into a PowerPoint presentation using default settings. ```r library(rmarkdown) library(officedown) render( "presentation.Rmd", output_format = rpptx_document(), output_file = "presentation.pptx" ) ``` -------------------------------- ### Get Default Style Name Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Retrieves the default style name for a given style type from the styles information. This is an internal function. ```r default_style(type, si) ``` -------------------------------- ### Create Basic PowerPoint Presentation Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Render an Rmd file into a PowerPoint presentation using the rpptx_document output format. Ensure both rmarkdown and officedown libraries are loaded. ```r library(rmarkdown) library(officedown) render("slides.Rmd", output_format = rpptx_document()) ``` -------------------------------- ### Configure List Styles for DOCX Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rdocx_document.md Specify ordered and unordered list styles using names from a reference DOCX. Set to NULL to use default styles. ```r lists = list( ol.style = NULL, # Ordered list style name (from reference_docx) ul.style = NULL # Unordered list style name (from reference_docx) ) ``` -------------------------------- ### Custom Placeholder and Background in PowerPoint Slide Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rpptx_document.md Embed a plot into a PowerPoint slide with a custom background color and placeholder type. This example assumes an R Markdown chunk with 'Title and Content' layout. ```r # In R Markdown chunk ```{r, layout="Title and Content", bg="lightblue", ph=officer::ph_location_type(type="body")} plot(mtcars$wt, mtcars$mpg) ``` ``` -------------------------------- ### Basic rpptx_document YAML Configuration Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Configure the output format for a PowerPoint presentation using YAML front matter. Specifies 'officedown::rpptx_document' as the output type. ```yaml --- title: "My Presentation" output: officedown::rpptx_document --- ``` -------------------------------- ### Use List Configuration in rdocx_document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Apply list styling configurations when creating a Word document using rdocx_document. ```r rdocx_document( lists = list( ol.style = "Heading 1", ul.style = "Heading 2" ) ) ``` -------------------------------- ### Configure List Styles Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use the 'lists' parameter to specify custom styles for ordered and unordered lists. Set to NULL to use default styles. ```r rdocx_document( lists = list( ol.style = NULL, # Ordered list style name ul.style = NULL # Unordered list style name ) ) ``` -------------------------------- ### Embed ggplot Plot as Editable Vector Graphic Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rpptx_document.md Wrap a ggplot object with dml() to render it as an editable DrawingML vector graphic in PowerPoint. Ensure the rvg package is installed and version 0.3.4 or higher for DrawingML support. ```r # In R Markdown chunk with pptx output library(rvg) # Wrap plot in dml() to create editable vector graphics dml(ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()) ``` -------------------------------- ### Render R Plot as DrawingML in PowerPoint Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/knit_print_methods.md Use `dml()` to render an R plot as an editable vector graphic in PowerPoint. Ensure pandoc and rvg are installed and that the output is an `rpptx_document`. The plot dimensions and placeholder location are determined by chunk options. ```r library(rvg) library(ggplot2) library(officedown) # In R Markdown chunk with rpptx_document output: # ```{r, layout="Title and Content"} dml(ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()) # ``` ``` -------------------------------- ### Directly Accessible officedown Functions Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Demonstrates direct calls to functions like rdocx_document(), rpptx_document(), knit_print_block(), and knit_print_run(). These functions are available for immediate use. ```r library(officedown) # These are directly accessible: rdocx_document() rpptx_document() knit_print_block(my_block) knit_print_run(my_run) # These are registered as S3 methods (automatic via knitr): knit_print(my_run) # Calls knit_print.run() knit_print(my_block) # Calls knit_print.block() ``` -------------------------------- ### List Raster Files in Directory Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Lists raster image files in a specified DrawingML directory. Returns a character vector of full paths to PNG files. This is an internal function. ```r list_raster_files(img_dir) ``` -------------------------------- ### Merging Default and User Table Styles Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Demonstrates how user-provided list elements override default values when merging with default configurations using `utils::modifyList`. ```r # User provides partial list user_tables <- list(style = "Light Grid") # Merged with defaults final_tables <- modifyList(tables_default_values, user_tables) # Result: all default fields except style is "Light Grid" ``` -------------------------------- ### Configure Page Size Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Set document page dimensions using the 'page_size' parameter. Specify width, height in inches, and orientation ('portrait' or 'landscape'). ```r rdocx_document( page_size = list( width = 8.5, # inches height = 11, # inches orient = "portrait" # or "landscape" ) ) ``` -------------------------------- ### Bookdown Site Rendering with Officedown Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/index.md Renders a Bookdown site, automatically utilizing officedown formats specified in the _output.yml configuration file for consistent output across documents. ```r render_site() ``` -------------------------------- ### Configure List Styling Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Define a list to configure ordered and unordered list styles in Word documents. ```r lists = list( ol.style = NULL, ul.style = NULL ) ``` -------------------------------- ### Include Local Image in Word Document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Demonstrates the correct way to include local images in a Word document using `knitr::include_graphics`. Remote URLs are not supported and will not work. ```r # ✓ Works knitr::include_graphics("local_image.png") # ✗ Does not work knitr::include_graphics("https://example.com/image.png") ``` -------------------------------- ### Rendering Officer Objects with officedown Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Shows how to create officer objects and have them rendered automatically by officedown's S3 methods when used in R Markdown chunks. Requires both 'officer' and 'officedown' packages. ```r library(officer) library(officedown) # Create officer objects my_run <- run_text("Bold", prop = run_properties(bold = TRUE)) my_block <- block_para(para_03 = my_run) # Render in R Markdown (automatic via knit_print methods) my_run # In chunk output my_block # In chunk output ``` -------------------------------- ### Custom Word Document with Template Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/index.md Creates a Word document using a custom template (reference_docx) for advanced styling and layout. Allows for custom table styles and plot alignment. ```r render("doc.Rmd", output_format = rdocx_document( reference_docx = "template.docx", tables = list(style = "CustomTable"), plots = list(align = "center") )) ``` -------------------------------- ### rpptx_document Defaults Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Default YAML configuration for rpptx_document, specifying layout and table conditional formatting. ```yaml layout: Title and Content master: Office Theme tcf: first_row: true first_column: false last_row: false last_column: false no_hband: false no_vband: true ``` -------------------------------- ### Configure Page Size Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Define a list to configure the page dimensions and orientation for Word documents. ```r page_size = list( width = 8.5, height = 11, orient = "portrait" ) ``` -------------------------------- ### Use Table Configuration in rdocx_document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Apply table styling configurations when creating a Word document using rdocx_document. ```r rdocx_document( tables = list( style = "Light Grid", layout = "autofit", caption = list( style = "Table Caption", pre = "Table" ) ) ) ``` -------------------------------- ### Basic DOCX Document Rendering Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rdocx_document.md Render an Rmd file to a DOCX document using the default rdocx_document format. Ensure the rmarkdown and officedown libraries are loaded. ```r library(rmarkdown) library(officedown) # Minimal example render( "document.Rmd", output_format = rdocx_document(), output_file = "document.docx" ) ``` -------------------------------- ### Discover Table Styles in Word Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use this snippet to list all available table styles in a Word document. Load the document first. ```r library(officer) # Load document doc <- read_docx("template.docx") # List all table styles styles_info(doc, type = "table") |> View() ``` -------------------------------- ### Custom Layout and Master for rpptx_document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rpptx_document.md Renders an R Markdown file into a PowerPoint presentation, specifying a custom slide layout and master theme. ```r library(rmarkdown) library(officedown) render( "presentation.Rmd", output_format = rpptx_document( layout = "Title and Content", master = "Office Theme" ), output_file = "presentation.pptx" ) ``` -------------------------------- ### Use a PowerPoint Template Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Specify a custom PowerPoint template (.pptx) to control slide layouts, master slides, theme colors, fonts, and table styles. If not provided, a built-in Office template is used. ```r rpptx_document(..., reference_doc = "path/to/template.pptx") ``` -------------------------------- ### Import Specific Functions with importFrom Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Imports specific functions from various packages using the importFrom mechanism. ```r importFrom(grDevices, dev.off) importFrom(knitr, asis_output, knit_print, opts_chunk, opts_current, opts_knit) importFrom(memoise, forget, memoise) importFrom(rmarkdown, pandoc_version) importFrom(rlang, eval_tidy) importFrom(rvg, dml, dml_pptx) importFrom(utils, getAnywhere, getFromNamespace, modifyList) importFrom(uuid, UUIDgenerate) importFrom(yaml, yaml.load) ``` -------------------------------- ### Construct Filename with Metadata Extension Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Constructs a filename by inserting a metadata extension before the original file extension. Useful for creating unique filenames for processed files. ```r file_with_meta_ext("document.Rmd", "knit") # Returns: "document.knit.Rmd" ``` -------------------------------- ### Configure Word Tables with officedown Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rdocx_document.md Define table styling, layout, and caption properties for Word documents. Use this to customize how tables are rendered, including their width, caption placement, and reference identifiers. ```r tables = list( style = "Table", # Word table style name layout = "autofit", # "autofit" or "fixed" width = 1, # Preferred width (0 to 1) topcaption = TRUE, # Caption position tab.lp = "tab:", # Reference identifier caption = list( style = "Table Caption", pre = "Table", sep = ":", tnd = 0, # Title depth for numbering tns = "-", # Title separator fp_text = fp_text_lite(bold = TRUE) ), conditional = list( first_row = TRUE, first_column = FALSE, last_row = FALSE, last_column = FALSE, no_hband = FALSE, no_vband = TRUE ) ) ``` -------------------------------- ### Set PowerPoint Output Format Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Specify the base format for PowerPoint output. Use 'rmarkdown::powerpoint_presentation' for standard output or 'bookdown::powerpoint_presentation2' for Bookdown's enhanced format. ```r rpptx_document(base_format = "rmarkdown::powerpoint_presentation") ``` -------------------------------- ### Configure Table Styling Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Define a list to configure table styling in Word documents, including layout, caption positioning, and conditional formatting. ```r tables = list( style = "Table", layout = "autofit", width = 1, topcaption = TRUE, tab.lp = "tab:", caption = list( style = "Table Caption", pre = "Table", sep = ":", tnd = 0, tns = "-", fp_text = officer::fp_text_lite(bold = TRUE) ), conditional = list( first_row = TRUE, first_column = FALSE, last_row = FALSE, last_column = FALSE, no_hband = FALSE, no_vband = TRUE ) ) ``` -------------------------------- ### API Reference Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/_COMPLETION_REPORT.txt Detailed function documentation for the officedown package. This section covers all exported functions, their signatures, parameters, and default values, ensuring users can directly interact with the package's capabilities. ```APIDOC ## API Reference Detailed function documentation for the officedown package. This section covers all exported functions, their signatures, parameters, and default values, ensuring users can directly interact with the package's capabilities. ``` -------------------------------- ### Full Package Imports Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Imports all functions from the 'officer' and 'xml2' packages. This makes functions from these packages available without explicit namespace qualification. ```R import(officer) import(xml2) ``` -------------------------------- ### Generate Temporary Image Directory Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Generates a temporary directory for storing raster images in DrawingML. This is an internal function. ```r get_img_dir() ``` -------------------------------- ### Basic rdocx_document YAML Configuration Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Configure the output format for a Word document using YAML front matter. Specifies 'officedown::rdocx_document' as the output type. ```yaml --- title: "My Document" output: officedown::rdocx_document --- ``` -------------------------------- ### Discover List Numbering Styles in Word Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use this snippet to list all available list numbering styles in a Word document. Load the document first. ```r library(officer) # Load document doc <- read_docx("template.docx") # List all list numbering styles styles_info(doc, type = "numbering") |> View() ``` -------------------------------- ### Set Default Section Properties Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Sets default section properties for the entire document body. This applies page size, orientation, and margins if no other sections are defined. ```r body_set_default_section(x, default_sect_properties) ``` -------------------------------- ### Map Word Styles Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use 'mapstyles' to map Word style names for replacement. This allows custom styles to be treated as standard ones. ```r rdocx_document( mapstyles = list( "Normal" = c("Author", "Date"), # Paragraphs with "Author"/"Date" style become "Normal" "Heading 1" = c("H1_custom") # "H1_custom" style becomes "Heading 1" ) ) ``` -------------------------------- ### R: knit_print.dml Method Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Renders DrawingML objects (editable vector graphics for PowerPoint). Requires specific Pandoc and rvg versions. ```R knit_print.dml(x, ...) ``` -------------------------------- ### Use Page Size Configuration in rdocx_document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/types.md Apply custom page size configurations when creating a Word document using rdocx_document. ```r rdocx_document( page_size = list( width = 8.27, height = 11.69, orient = "portrait" ) ) ``` -------------------------------- ### Render Word Document with Custom Styles and Captions Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Use this snippet to render an R Markdown document to Word, applying custom styles from a reference DOCX file for tables and plots, and setting up caption prefixes. ```r library(rmarkdown) library(officedown) render( "document.Rmd", output_format = rdocx_document( reference_docx = "my_template.docx", tables = list( style = "CustomTable", caption = list(pre = "Table") ), plots = list( align = "center", caption = list(pre = "Figure") ) ) ) ``` -------------------------------- ### Enable Reference Numbering Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Set 'reference_num' to TRUE to display cross-references as section numbers (e.g., '3.2'). Set to FALSE to show section titles. ```r rdocx_document(reference_num = TRUE) ``` -------------------------------- ### Load Reference PowerPoint Document (Memoized) Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Memoized function to load the reference PowerPoint document. It caches the presentation in memory for efficient repeated access. ```r get_reference_pptx() ``` -------------------------------- ### Internal Utilities Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/_COMPLETION_REPORT.txt Reference for internal helper functions within the officedown package. While primarily for internal use, this documentation can provide insights into the package's implementation details. ```APIDOC ## Internal Utilities Reference for internal helper functions within the officedown package. While primarily for internal use, this documentation can provide insights into the package's implementation details. ``` -------------------------------- ### Discover Slide Layouts in PowerPoint Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use this snippet to list all available slide layouts in a PowerPoint presentation. Load the presentation first. ```r library(officer) # Load presentation prs <- read_pptx("template.pptx") # List all slide layouts layout_summary(prs) |> View() ``` -------------------------------- ### Configure Table Styles Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Customize the appearance of data frame output as tables. Options include style, layout, width, caption prefix, and conditional formatting for specific cells. ```R rdocx_document( tables = list( style = "Table", layout = "autofit", width = 1, topcaption = TRUE, tab.lp = "tab:", caption = list( style = "Table Caption", pre = "Table", sep = ":", tnd = 0, tns = "-", fp_text = officer::fp_text_lite(bold = TRUE) ), conditional = list( first_row = TRUE, first_column = FALSE, last_row = FALSE, last_column = FALSE, no_hband = FALSE, no_vband = TRUE ) ) ) ``` -------------------------------- ### R: knit_print.run Method Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Renders officer::run objects (text formatting elements). Called by knitr. ```R knit_print.run(x, ...) ``` -------------------------------- ### Configure Page Margins Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Define document margins with the 'page_margins' parameter. Includes settings for top, bottom, left, right, header, footer, and gutter margins in inches. ```r rdocx_document( page_margins = list( top = 1, bottom = 1, left = 1.25, right = 1.25, header = 0.5, footer = 0.5, gutter = 0 ) ) ``` -------------------------------- ### Integrate with Bookdown for DOCX Output Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/rdocx_document.md Render an Rmd file to DOCX using officedown's rdocx_document, specifying bookdown::word_document2 as the base format. Requires bookdown and officedown libraries. ```r library(rmarkdown) library(bookdown) library(officedown) # Use with bookdown word_document2 render( "document.Rmd", output_format = officedown::rdocx_document( base_format = "bookdown::word_document2" ), output_file = "document.docx" ) ``` -------------------------------- ### Configure Table of Contents Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Enable and control the depth of the table of contents. Set 'toc = TRUE' to generate a TOC and 'toc_depth' to specify the heading levels (1-9) to include. ```R rdocx_document(..., toc = TRUE, toc_depth = 2) ``` -------------------------------- ### Advanced rdocx_document YAML Configuration Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Configure advanced options for Word document generation, including reference document, table of contents, table styles, plot alignment, page size, and margins. ```yaml --- title: "My Document" output: officedown::rdocx_document: reference_docx: "template.docx" toc: true toc_depth: 2 tables: style: "Light Grid" topcaption: false plots: align: "center" topcaption: true page_size: width: 8.5 height: 11 orient: "portrait" page_margins: top: 1 bottom: 1 left: 1.25 right: 1.25 --- ``` -------------------------------- ### Discover Paragraph Styles in Word Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Use this snippet to list all available paragraph styles in a Word document. Load the document first. ```r library(officer) # Load document doc <- read_docx("template.docx") # List all paragraph styles styles_info(doc, type = "paragraph") |> View() ``` -------------------------------- ### Minimal Word Document Creation Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/index.md Generates a basic Word document from an Rmd file using the rdocx_document format. Requires the rmarkdown and officedown packages. ```r library(rmarkdown) library(officedown) render("doc.Rmd", output_format = rdocx_document()) ``` -------------------------------- ### Import Entire Officer Namespace Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Imports the entire 'officer' namespace to make its functions available within the officedown namespace. ```r import(officer) # Re-exports entire officer namespace ``` -------------------------------- ### Import from xml2 Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Imports the 'xml2' package, which is used for XML document processing throughout the officedown package. ```r import(xml2) ``` -------------------------------- ### Retrieve Function by Name Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Retrieves a function object from a package namespace using its name. Supports both simple and namespaced function names. ```r get_fun(x) ``` -------------------------------- ### Extract and Convert Block Macros to OOXML Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Internal function to extract and convert block macros to OOXML. Specific parameters for text, regex, filename, and type are used. ```r ooxml_values(txt, regex, fname, type) ``` -------------------------------- ### Set Base Output Format Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/configuration.md Specify the base R Markdown format for Word output. Use 'rmarkdown::word_document' for standard output or 'bookdown::word_document2' for Bookdown format with numbered sections. ```R rdocx_document(base_format = "rmarkdown::word_document") ``` -------------------------------- ### Load Reference Word Document (Memoized) Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Memoized function to load the reference Word document. It caches the document in memory for efficient repeated access. ```r get_reference_rdocx() ``` -------------------------------- ### Cross-References in Bookdown Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/README.md Demonstrates how to use Bookdown's cross-referencing syntax within an R Markdown document to refer to tables, figures, and sections. This enables automatic updating of references. ```markdown # Methods {#methods} (results in Table \@ref(tab:mydata)) ```{r mydata, tab.cap="Data summary"} head(mtcars) ``` See \@ref(methods) for methodology. ``` -------------------------------- ### Apply Custom List Styles to Word Document Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/api-reference/internal_utilities.md Applies custom unordered and ordered list styles to a Word document by modifying its internal numbering XML. Use when custom list formatting is required beyond default pandoc styles. ```r process_list_settings(rdoc, ul_style = NULL, ol_style = NULL) ``` -------------------------------- ### R: knit_print.data.frame Method Source: https://github.com/davidgohel/officedown/blob/main/_autodocs/exports-summary.md Renders data frames as formatted tables with captions. Handles specific behavior for Word and PowerPoint. ```R knit_print.data.frame(x, ...) ```