inst/examples/example_print_docx.R

library(officer)

# This example demonstrates how to create
# an small document -----

## Create a new Word document
doc <- read_docx()
doc <- body_add_par(doc, "hello world")
## Save the document
output_file <- print(doc, target = tempfile(fileext = ".docx"))

# preview mode: save to temp file and open locally ----
## Not run:
# print(doc, preview = TRUE)

Try the officer package in your browser

Any scripts or data that you put into this service are public.

officer documentation built on Jan. 17, 2026, 1:06 a.m.