# NOT RUN {
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
# }
Run the code above in your browser using DataLab