write_report | R Documentation |
This function writes a report_spec object to the file system, using the specifications provided in the object.
write_report(
x,
file_path = NULL,
output_type = NULL,
preview = NULL,
log = TRUE
)
x |
The report object to write. |
file_path |
The file name and path to write the report to. If supplied,
this parameter overrides the |
output_type |
The output file type. This parameter will override
the |
preview |
Whether to write the entire report, or a report preview. A report preview is a subset of pages of the report. The default value is NULL, meaning the entire report will be written. You may also pass a number of pages to write. For example, passing the number 1 will print the first page, while passing a 5 will print the first five pages. |
log |
Whether the function should log itself automatically, if the logr package is available. This parameter is used internally. Default is TRUE. |
The function renders the report in the requested format, and writes it
to the location specified in the report file_path
parameter. Attempts
to write an object that is not of class "report_spec" will generate an error.
The write_report
function is a driver for very complex set of
rendering functions. The rendering functions
perform most of the advanced functionality of the reporter package:
generating spanning headers, page wrapping and breaking, creating stub
columns, etc. When things go wrong, they will usually go wrong during this
function call. For that reason, although this function can be part of
the pipeline that creates the report object, it is best to call
write_report
independently, to help isolate any issues from the
report definition procedure.
The report spec, with settings modified during rendering. These modified settings can sometimes be useful for documentation, and for debugging issues with the procedure.
Other report:
add_content()
,
create_report()
,
footnotes()
,
options_fixed()
,
page_by()
,
page_footer()
,
page_header()
,
print.report_spec()
,
set_margins()
,
title_header()
,
titles()
library(reporter)
library(fmtr)
library(magrittr)
# Create temp file path
tmp <- file.path(tempdir(), "beaver2.txt")
# Take Sample of Data
dat <- beaver2[sample(1:100, 15), ]
# Create format for active variable
fmt <- value(condition(x == 0, "No"),
condition(x == 1, "Yes"))
# Create the table
tbl <- create_table(dat) %>%
titles("Table 1.0", "BEAVERS Sample Report") %>%
column_defaults(width = .75) %>%
define(day, label = "Day", format = "Day %s") %>%
define(time, label = "Time") %>%
define(temp, label = "Temperature", width = 1, format = "%.1f") %>%
define(activ,label = "Active", format = fmt) %>%
footnotes("* NOTE: Data on beaver habits")
# Create the report object
rpt <- create_report(tmp) %>%
add_content(tbl, align = "left")
# Write the report to the file system
res <- write_report(rpt)
# Write the modified report object to the console
print(res)
# Write the report to console
writeLines(readLines(tmp, encoding = "UTF-8"))
# Table 1.0
# BEAVERS Sample Report
#
# Day Time Temperature Active
# -----------------------------------------
# Day 307 1020 37.2 No
# Day 307 1030 37.2 No
# Day 307 940 36.7 No
# Day 307 1340 37.1 No
# Day 307 1410 37.2 No
# Day 307 1400 37.1 No
# Day 307 1130 36.9 No
# Day 307 1140 37.0 No
# Day 307 1120 37.0 No
# Day 307 1000 37.1 No
# Day 307 1250 37.0 No
# Day 307 2100 37.9 Yes
# Day 307 1210 37.0 No
# Day 307 1740 38.0 Yes
# Day 308 130 37.8 Yes
#
# * NOTE: Data on beaver habits
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.