Learn R Programming

crosstable (version 0.3.2)

body_add_list: Add a list to an officer document

Description

Add a list to an officer document

Usage

body_add_list(doc, value, ordered = FALSE, style = NULL, ...)

body_add_list_item(doc, value, ordered = FALSE, style = NULL, ...)

Arguments

doc

a docx object

value

a character (body_add_list()) or a string (body_add_list_item)

ordered

if TRUE, adds an ordered list, if FALSE, adds a bullet list

style

specify the style manually, overriding ordered. A better way is to set options crosstable_style_list_ordered and crosstable_style_list_unordered globally.

...

Value

The docx object doc

Details

Ordered lists and bullet lists are not supported by the default officer template (see https://github.com/davidgohel/officer/issues/262). You have to manually set custom styles matching those list in a custom Word template file. Then, you can use either the style argument or crosstable options. See examples for more details.

Examples

Run this code
# NOT RUN {
#For this example to work, `my_template.docx` should include styles named 
#`ordered_list` and `unordered_list`

library(officer)
library(crosstable)
options(crosstable_style_list_ordered="ordered_list")
options(crosstable_style_list_unordered="unordered_list")

read_docx("my_template.docx") %>%
 body_add_list(c("Numbered item 1", "Numbered item 2"), ordered = TRUE) %>%
 body_add_list_item("Numbered item 3", ordered = TRUE) %>%
 body_add_list(c("Bullet item 1", "Bullet item 2"), ordered = FALSE) %>%
 body_add_list_item("Bullet item 3", ordered = FALSE) %>%
 write_and_open()
# }

Run the code above in your browser using DataLab