Type: Package
Title: Insert 'gt' Tables into Word Documents
Version: 0.1.2
Description: Insert tables created by the 'gt' R package into 'Microsoft Word' documents. This gives users the ability to add to their existing word documents the tables made in 'gt' using the familiar 'officer' package and syntax from the 'officeverse'.
License: Apache License (≥ 2)
Encoding: UTF-8
Imports: gt (≥ 0.8.0), magrittr, officer, rlang, xml2
Suggests: testthat (≥ 3.0.0), dplyr, tibble, covr
RoxygenNote: 7.2.1
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2024-09-26 17:45:53 UTC; ehh82309
Author: Ellis Hughes ORCID iD [aut, cre], GlaxoSmithKline Research & Development Limited [cph, fnd]
Maintainer: Ellis Hughes <ellis.h.hughes@gsk.com>
Repository: CRAN
Date/Publication: 2024-09-26 18:00:06 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling 'rhs(lhs)'.


Add 'gt' table into a Word document

Description

Add a 'gt' table into a Word document. The table will be processed using the as_word function then inserted either after, before, or on the cursor location.

Usage

body_add_gt(
  x,
  value,
  align = "center",
  pos = c("after", "before", "on"),
  caption_location = c("top", "bottom", "embed"),
  caption_align = "left",
  split = FALSE,
  keep_with_next = TRUE
)

Arguments

x

'rdocx' object

value

'gt_tbl' object

align

left, center (default) or right.

pos

where to add the gt table relative to the cursor, one of "after" (default), "before", "on" (end of line).

caption_location

top (default), bottom, or embed indicating if the title and subtitle should be listed above, below, or be embedded in the table

caption_align

left (default), center, or right. Alignment of caption (title and subtitle). Used when 'caption_location' is not "embed".

split

set to TRUE if you want to activate Word option 'Allow row to break across pages'.

keep_with_next

Word option 'keep rows together' can be activated when TRUE. It avoids page break within tables.

Value

An updated rdocx object with a 'gt' table inserted

See Also

flextable::body_add_flextable()

Examples


 library(officer)
 library(gt)

 gt_tbl <- gt(head(exibble))

 doc <- read_docx()
 doc <- body_add_gt(doc, value = gt_tbl)
 fileout <- tempfile(fileext = ".docx")
 print(doc, target = fileout)