Learn R Programming

crosstable (version 0.3.2)

body_add_normal: Add a new paragraph with default style

Description

Add a new paragraph in an officer document with default style. Variables can be inserted as multiple strings (paste() style) or enclosed by braces (glue() style). References to any bookmark can be inserted using the syntax "\@ref(bookmark)". See an example in body_add_table_legend().

Usage

body_add_normal(doc, ..., .sep = "", squish = TRUE)

Arguments

doc

the doc object (created with the read_docx function of officer package)

...

one or several character strings, pasted using .sep. As with glue::glue(), expressions enclosed by braces will be evaluated as R code. If more than one variable is passed, all should be of length 1.

.sep

Separator used to separate elements.

squish

Whether to squish the result (remove trailing and repeated spaces). Default to TRUE. Allows to add multiline paragraph without breaking the string.

Value

a new doc object

The docx object doc

Examples

Run this code
# NOT RUN {
library(officer)
library(crosstable)

info_rows = c("Also, table iris has {nrow(iris)} rows.", 
              "And table mtcars has {nrow(mtcars)} rows.")
doc = read_docx()  %>% 
    body_add_normal("Table iris has", ncol(iris), "columns.", .sep=" ") %>% #paste style
    body_add_normal("However, table mtcars has {ncol(mtcars)} columns") %>% #glue style
    body_add_normal(info_rows)                                              #vector style
#write_and_open(doc)
# }

Run the code above in your browser using DataLab