add_content: Add content to a report

Description Usage Arguments Details Value See Also Examples

View source: R/report_spec.r

Description

This function adds an object to the report content list. A report will accept multiple pieces of content. The add_content function also controls overall alignment of the content on the page, and whether there is a page break before or after.

Usage

1
2
3
4
5
6
7
add_content(
  x,
  object,
  page_break = TRUE,
  align = "center",
  blank_row = "below"
)

Arguments

x

The report_spec to append content to.

object

The object to append.

page_break

Whether to add a page break after the object. Valid values are TRUE or FALSE. You can manipulate the page_break parameter to add multiple objects to the same page.

align

How to align the content. Valid values are 'left', 'right', 'center', and 'centre'.

blank_row

Whether to put a blank row above or below the content. Valid values are 'above', 'below', 'both', or 'none'.

Details

The add_content function adds a piece of content to a report. For a text report, valid objects are a table or text object. See create_table or create_text for further information on how to create these objects.

Content will be appended to the report in the order it is added. By default, a page break is added after the content. You can stack two pieces of content together closely by setting the page_break parameter to FALSE, and the blank_row parameter to "none".

Value

The modified report_spec.

See Also

create_table and create_text to create content for a report.

Other report: create_report(), footnotes(), options_fixed(), page_footer(), page_header(), set_margins(), titles(), write_report()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library(rptr)
library(magrittr)

# Create temp file path
tmp <- file.path(tempdir(), "mtcars.txt")

# Create the report object
rpt <- create_report(tmp) %>% 
  titles("MTCARS Sample Data", align = "left") %>% 
  add_content(create_table(mtcars[1:5, ]), 
              page_break = FALSE, align = "left", blank_row = "none") %>% 
  add_content(create_table(mtcars[6:10, ], headerless=TRUE), 
              page_break = FALSE, align = "left") %>% 
  add_content(create_text("* NOTE: Above table is actually two tables stacked.")) 

# Write the report to the file system
write_report(rpt)

# Write report to console
writeLines(readLines(tmp))

# MTCARS Sample Data
# 
#  mpg    cyl   disp     hp   drat     wt   qsec     vs     am   gear   carb
#----------------------------------------------------------------------------
#   21      6    160    110    3.9   2.62  16.46      0      1      4      4
#   21      6    160    110    3.9  2.875  17.02      0      1      4      4
# 22.8      4    108     93   3.85   2.32  18.61      1      1      4      1
# 21.4      6    258    110   3.08  3.215  19.44      1      0      3      1
# 18.7      8    360    175   3.15   3.44  17.02      0      0      3      2
# 18.1      6    225    105   2.76   3.46  20.22      1      0      3      1
# 14.3      8    360    245   3.21   3.57  15.84      0      0      3      4
# 24.4      4  146.7     62   3.69   3.19     20      1      0      4      2
# 22.8      4  140.8     95   3.92   3.15   22.9      1      0      4      2
# 19.2      6  167.6    123   3.92   3.44   18.3      1      0      4      4
# 
# * NOTE: Above table is actually two tables stacked.

dbosak01/reporter documentation built on Sept. 22, 2020, 3:34 p.m.