### Install officedown Package Source: https://davidgohel.github.io/officedown/index.html Install the officedown package from GitHub using the remotes package. ```r remotes::install_github("davidgohel/officedown") ``` -------------------------------- ### Basic officedown Example Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Renders a minimal R Markdown file to a .docx document using officedown. Requires pandoc version 2.0 or higher. ```r # rdocx_document basic example ----- library(rmarkdown) library(officedown) if (pandoc_available() && pandoc_version() >= numeric_version("2.0")) { # minimal example ----- example <- system.file( package = "officedown", "examples/minimal_word.Rmd" ) rmd_file <- tempfile(fileext = ".Rmd") file.copy(example, to = rmd_file) docx_file <- tempfile(fileext = ".docx") render(rmd_file, output_file = docx_file, quiet = TRUE) } ``` -------------------------------- ### Illustrate officedown Word Features Source: https://davidgohel.github.io/officedown/index.html Copy and explore the example bookdown project to see officedown's Word features in action. This involves copying the example directory and then rendering the bookdown site. ```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 ``` -------------------------------- ### Render R Markdown to PowerPoint Source: https://davidgohel.github.io/officedown/reference/rpptx_document.html Example of rendering an R Markdown file to a PowerPoint presentation using rpptx_document. Ensures pandoc is available and meets version requirements before rendering. ```r library(rmarkdown) run_ok <- pandoc_available() && pandoc_version() > numeric_version("2.4") if(run_ok){ example <- system.file(package = "officedown", "examples/minimal_powerpoint.Rmd") rmd_file <- tempfile(fileext = ".Rmd") file.copy(example, to = rmd_file) pptx_file_1 <- tempfile(fileext = ".pptx") render(rmd_file, output_file = pptx_file_1) } #> #> #> processing file: file1fc279eaa607.Rmd #> 1/14 #> 2/14 [setup] #> 3/14 #> 4/14 [unnamed-chunk-1] #> 5/14 #> 6/14 [unnamed-chunk-2] #> 7/14 #> 8/14 [plot1] #> 9/14 #> 10/14 [unnamed-chunk-3] #> 11/14 #> 12/14 [unnamed-chunk-4] #> 13/14 #> 14/14 [unnamed-chunk-5] #> output file: file1fc279eaa607.knit.md #> /opt/hostedtoolcache/pandoc/3.1.11/x64/pandoc +RTS -K512m -RTS file1fc279eaa607.knit.md --to pptx --from markdown+autolink_bare_uris+tex_math_single_backslash --output /tmp/RtmpNiKGlz/file1fc268fbc429.pptx --reference-doc /tmp/RtmpNiKGlz/file1fc2e48d3b3.pptx #> #> Output created: /tmp/RtmpNiKGlz/file1fc268fbc429.pptx ``` -------------------------------- ### Force Printing Runs in R Markdown Source: https://davidgohel.github.io/officedown/reference/knit_print_run.html Use `knit_print_run` to force printing of runs within loops in R Markdown. Ensure `results='asis'` is set in the chunk options. This example demonstrates rendering an Rmd file that uses this functionality. ```R library(rmarkdown) rmd_file_src <- system.file( package = "officedown", "examples", "word_loop.Rmd") rmd_file_des <- tempfile(fileext = ".Rmd") if(pandoc_available()){ file.copy(rmd_file_src, to = rmd_file_des) docx_file_1 <- tempfile(fileext = ".docx") render(rmd_file_des, output_file = docx_file_1, quiet = TRUE) if(file.exists(docx_file_1)){ message("file ", docx_file_1, " has been written.") } } #> file /tmp/RtmpNiKGlz/file1fc276cd62b5.docx has been written. ``` -------------------------------- ### rpptx_document() Source: https://davidgohel.github.io/officedown/reference/index.html Creates an advanced R Markdown output format for Microsoft PowerPoint presentations. ```APIDOC ## rpptx_document() ### Description Advanced R Markdown PowerPoint Format. ### Usage ```r rpptx_document(toc = TRUE, ...) ``` ### Arguments * `toc` (logical) - Whether to include a table of contents. Defaults to TRUE. * `...` - Additional arguments passed to the underlying R Markdown format. ``` -------------------------------- ### Read Word Document Styles Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Use the 'officer' package to read stylenames from a Word template. Change 'ref_docx_default' to specify a different reference document. ```r library(officer) docx_file <- system.file(package = "officer", "template", "template.docx") doc <- read_docx(docx_file) ``` -------------------------------- ### Default Table Styling Options Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Configure default styling for tables, including style, layout, width, caption placement, and conditional formatting for rows and columns. This YAML configuration is used when the 'tables' argument is provided to rdocx_document. ```yaml style: Table layout: autofit width: 1.0 topcaption: true tab.lp: 'tab:' caption: style: Table Caption pre: 'Table' sep: ':' tnd: 0 tns: '-' fp_text: !expr officer::fp_text_lite(bold = TRUE) conditional: first_row: true first_column: false last_row: false last_column: false no_hband: false no_vband: true ``` -------------------------------- ### rdocx_document() Source: https://davidgohel.github.io/officedown/reference/index.html Creates an advanced R Markdown output format for Microsoft Word documents. ```APIDOC ## rdocx_document() ### Description Advanced R Markdown Word Format. ### Usage ```r rdocx_document(toc = TRUE, ...) ``` ### Arguments * `toc` (logical) - Whether to include a table of contents. Defaults to TRUE. * `...` - Additional arguments passed to the underlying R Markdown format. ``` -------------------------------- ### Extract List Styles Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Retrieve list (numbering) stylenames from a Word document object using styles_info(). Displays the first 6 columns of the output. ```r styles_info(doc, type = "numbering")[, 1:6] ``` -------------------------------- ### Default List Styles for Rdocx Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html YAML configuration for default list styles in rdocx documents. Sets the styles for ordered and unordered lists. ```yaml output: officedown::rdocx_document: lists: ol.style: null ul.style: null ``` -------------------------------- ### Define R Markdown PowerPoint Document Format Source: https://davidgohel.github.io/officedown/reference/rpptx_document.html Use rpptx_document to define a custom R Markdown output format for PowerPoint. Specify default slide layout, master, and conditional formatting for tables. Arguments are passed to rmarkdown::powerpoint_presentation. ```r rpptx_document( base_format = "rmarkdown::powerpoint_presentation", layout = "Title and Content", master = "Office Theme", tcf = list(), ... ) ``` -------------------------------- ### R Markdown YAML Configuration for officedown Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Configure R Markdown YAML to specify officedown as the output format and customize document elements like tables, plots, lists, styles, page size, and margins. ```yaml --- output: officedown::rdocx_document: reference_docx: pandoc_template.docx tables: style: Table layout: autofit width: 1.0 topcaption: true tab.lp: 'tab:' caption: style: Table Caption pre: 'Table ' sep: ': ' tnd: 0 tns: '-' fp_text: !expr officer::fp_text_lite(bold = TRUE) plots: style: Normal align: center fig.lp: 'fig:' topcaption: false caption: style: Image Caption pre: 'Figure ' sep: ': ' tnd: 0 tns: '-' fp_text: !expr officer::fp_text_lite(bold = TRUE) lists: ol.style: null ul.style: null mapstyles: Normal: ['First Paragraph', 'Author', 'Date'] page_size: width: 11906 / 1440 height: 16838 / 1440 orient: "portrait" page_margins: bottom: 1 top: 1 right: 1417 / 1440 left: 1417 / 1440 header: 708 / 1440 footer: 708 / 1440 gutter: 0 / 1440 reference_num: true --- ``` -------------------------------- ### Extract Table Styles Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Retrieve table stylenames from a Word document object using styles_info(). Displays the first 6 columns of the output. ```r styles_info(doc, type = "table")[, 1:6] ``` -------------------------------- ### knit_print_run() Source: https://davidgohel.github.io/officedown/reference/index.html Forces the output of a code chunk to be printed during the knitting process. ```APIDOC ## knit_print_run() ### Description Force Run Printing while Knitting. ### Usage ```r knit_print_run(x, ...) ``` ### Arguments * `x` - The object to be printed. * `...` - Additional arguments. ``` -------------------------------- ### officedown Package Citation (BibTeX) Source: https://davidgohel.github.io/officedown/authors.html Use this BibTeX entry for citing the officedown R package in academic work. Ensure the version and URL are up-to-date. ```bibtex @Manual{ title = {officedown: Enhanced 'R Markdown' Format for 'Word' and 'PowerPoint'}, author = {David Gohel and Noam Ross}, year = {2025}, note = {R package version 0.4.1}, url = {https://ardata-fr.github.io/officeverse/}, } ``` -------------------------------- ### Custom List Styles for Rdocx Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html YAML configuration for custom list styles in rdocx documents. Assigns specific styles for ordered and unordered lists based on available numbering styles. ```yaml output: officedown::rdocx_document: lists: ol.style: 'Default ol' ul.style: 'Default ul' ``` -------------------------------- ### Reading Numbering Styles with officer Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html R code to read available numbering styles from a Word document template using the officer package. This helps in identifying valid style names for lists. ```r library(officer) docx_file <- system.file( package = "officedown", "examples", "bookdown", "template.docx" ) doc <- read_docx(docx_file) styles_info(doc, type = "numbering")[, 1:6] #> style_type style_id style_name base_on is_custom is_default #> 13 numbering Aucuneliste No List FALSE TRUE #> 40 numbering Defaultul Default ul Aucuneliste TRUE FALSE #> 41 numbering Defaultol Default ol Aucuneliste TRUE FALSE ``` -------------------------------- ### Extract Paragraph Styles Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Retrieve paragraph stylenames from a Word document object using styles_info(). Displays the first 6 columns of the output. ```r styles_info(doc, type = "paragraph")[, 1:6] ``` -------------------------------- ### knit_print_block() Source: https://davidgohel.github.io/officedown/reference/index.html Forces a specific block of code to be printed during the knitting process. ```APIDOC ## knit_print_block() ### Description Force Block Printing while Knitting. ### Usage ```r knit_print_block(x, ...) ``` ### Arguments * `x` - The object to be printed. * `...` - Additional arguments. ``` -------------------------------- ### Default Plot Options for Rdocx Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html YAML configuration for default plot styling in rdocx documents. Specifies paragraph styles for graphics and captions, alignment, and caption prefix. ```yaml style: Normal align: center topcaption: false fig.lp: 'fig:' caption: style: Image Caption pre: 'Figure ' sep: ': ' tnd: 0 tns: '-' fp_text: !expr officer::fp_text_lite(bold = TRUE) ``` -------------------------------- ### Define R Markdown Word Document Format Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html Use rdocx_document to create a custom R Markdown output format for Word. It allows for advanced formatting of tables, plots, and lists, and can be based on other formats like bookdown::word_document2. ```R rdocx_document( base_format = "rmarkdown::word_document", tables = list(), plots = list(), lists = list(), mapstyles = list(), page_size = NULL, page_margins = NULL, reference_num = TRUE, ... ) ``` -------------------------------- ### knit_print_block Function Source: https://davidgohel.github.io/officedown/reference/knit_print_block.html Forces the printing of block objects when knitting R Markdown documents. This function is particularly useful when working with loops to ensure that each block is rendered. It should be used in conjunction with the `results='asis'` chunk option. ```APIDOC ## knit_print_block ### Description Forces the printing of block objects when knitting R Markdown documents. This function is particularly useful when working with loops to ensure that each block is rendered. It should be used in conjunction with the `results='asis'` chunk option. ### Usage ```R knit_print_block(x, ...) ``` ### Arguments * `x` (block object): A block object, which is the result of a block function from the officer package. * `...` (unused arguments): Additional arguments that are not used by this function. ### Value None. The function only prints XML code. ### See Also * `knit_print_run()`: Another function that forces printing. ### Examples ```R library(rmarkdown) rmd_file_src <- system.file(package = "officedown", "examples", "word_loop.Rmd") rmd_file_des <- tempfile(fileext = ".Rmd") if(pandoc_available()){ file.copy(rmd_file_src, to = rmd_file_des) docx_file_1 <- tempfile(fileext = ".docx") render(rmd_file_des, output_file = docx_file_1, quiet = TRUE) if(file.exists(docx_file_1)){ message("file ", docx_file_1, " has been written.") } } ``` ``` -------------------------------- ### Force Printing of Officer Blocks Source: https://davidgohel.github.io/officedown/reference/knit_print_block.html Use knit_print_block to force the printing of officer package blocks when knitting R Markdown documents, particularly within loops. Ensure the R Markdown chunk option `results='asis'` is set. ```R library(rmarkdown) rmd_file_src <- system.file( package = "officedown", "examples", "word_loop.Rmd") rmd_file_des <- tempfile(fileext = ".Rmd") if(pandoc_available()){ file.copy(rmd_file_src, to = rmd_file_des) docx_file_1 <- tempfile(fileext = ".docx") render(rmd_file_des, output_file = docx_file_1, quiet = TRUE) if(file.exists(docx_file_1)){ message("file ", docx_file_1, " has been written.") } } #> file /tmp/RtmpNiKGlz/file1fc21c35ad73.docx has been written. ``` -------------------------------- ### rdocx_document Function Source: https://davidgohel.github.io/officedown/reference/rdocx_document.html The rdocx_document function allows for advanced formatting of R Markdown documents converted to Word. It extends the base rmarkdown::word_document() function with options for tables, plots, lists, and custom styles. ```APIDOC ## rdocx_document() ### Description 'R Markdown' Format for converting from 'R Markdown' document to an MS Word document. The function enhances the output offered by `rmarkdown::word_document()` with advanced formatting features. ### Usage ```R rdocx_document( base_format = "rmarkdown::word_document", tables = list(), plots = list(), lists = list(), mapstyles = list(), page_size = NULL, page_margins = NULL, reference_num = TRUE, ... ) ``` ### Arguments * `base_format` (character): The format to be used as a base document for 'officedown'. Default to `word_document` but can also be `word_document2()` from bookdown. When the `base_format` used is `bookdown::word_document2`, the `number_sections` parameter is automatically set to `FALSE`. Indeed, if you want numbered titles, you are asked to use a Word document template with auto-numbered titles (the title styles of the default `rdocx_document' template are already set to FALSE). * `tables` (list): See section 'Tables' below. * `plots` (list): See section 'Plots' below. * `lists` (list): See section 'Lists' below. * `mapstyles` (list): A named list of style to be replaced in the generated document. `list("Normal" = c("Author", "Date"))` will result in a document where all paragraphs styled with stylename "Date" and "Author" will be then styled with stylename "Normal". * `page_size`, `page_margins` (NULL): Default page and margins dimensions. If not null (the default), these values are used to define the default Word section. See `officer::page_size()` and `officer::page_mar()`. * `reference_num` (logical): If `TRUE`, text for references to sections will be the section number (e.g. '3.2'). If FALSE, text for references to sections will be the text (e.g. 'section title'). * `...`: Arguments used by `word_document`. ### Value R Markdown _output format_ to pass to render. ### Tables A list that can contain few items to style tables and table captions. Missing items will be replaced by default values. Possible items are the following: * `style` (character): The Word stylename to use for tables. * `layout` (character): 'autofit' or 'fixed' algorithm. See `table_layout`. * `width` (numeric): Value of the preferred width of the table in percent (base 1). * `topcaption` (logical): Caption will appear before (on top of) the table. * `tab.lp` (character): Caption table sequence identifier. All table captions are supposed to have the same identifier. It makes possible to insert list of tables. It is also used to prefix your 'bookdown' cross-reference call; if `tab.lp` is set to "tab:", a cross-reference to table with id "xxxxx" is written as `\@ref(tab:xxxxx)`. It is possible to set the value to your default Word value (in French for example it is "Tableau", in German it is "Tabelle"), you can then add manually a list of tables (go to the "References" tab and select menu "Insert Table of Figures"). * `caption` (list): Caption options, i.e.: * `style` (character): Word stylename to use for table captions. * `pre` (character): Prefix for numbering chunk (default to "Table "). * `sep` (character): Suffix for numbering chunk (default to ": "). * `tnd` (numeric): (only applies if positive. )Inserts the number of the last title of level `tnd` (i.e. 4.3-2 for figure 2 of chapter 4.3). * `tns` (character): Separator to use between title number and table number. Default is "-". * `fp_text` (officer::fp_text_lite): Text formatting properties to apply to caption prefix - see `officer::fp_text_lite()`. * `conditional` (list): A list of named logical values: * `first_row` and `last_row`: apply or remove formatting from the first or last row in the table * `first_column` and `last_column`: apply or remove formatting from the first or last column in the table * `no_hband` and `no_vband`: don't display odd and even rows or columns with alternating shading for ease of reading. Default value is (in YAML format): ```yaml style: Table layout: autofit width: 1.0 topcaption: true tab.lp: 'tab:' caption: style: Table Caption pre: 'Table' sep: ':' tnd: 0 tns: "-" fp_text: !expr officer::fp_text_lite(bold = TRUE) conditional: first_row: true first_column: false last_row: false last_column: false no_hband: false no_vband: true ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.