library(reporter)
library(magrittr)
# Create a temporary file
tmp <- file.path(tempdir(), "iris.txt")
# Prepare data
dat <- iris[sample(1:150, 15), c(5, 1, 2, 3, 4)]
dat <- dat[order(dat$Species), ]
# Define table
tbl <- create_table(dat) %>%
titles("Table 3.2", "IRIS Sample Report") %>%
spanning_header(2, 3, label = "Sepal") %>%
spanning_header(4, 5, label = "Petal") %>%
column_defaults(2:5, format = "%.1f") %>%
define(Species, align = "left", dedupe = TRUE, blank_after = TRUE) %>%
define(Sepal.Length, label = "Length") %>%
define(Sepal.Width, label = "Width") %>%
define(Petal.Length, label = "Length") %>%
define(Petal.Width, label = "Width") %>%
footnotes("* From Fisher's Iris Dataset")
# Define report
rpt <- create_report(tmp, orientation="portrait") %>%
options_fixed(blank_margins = TRUE) %>%
set_margins(top = 1, bottom =1) %>%
add_content(tbl, align = "left")
# Write the report
write_report(rpt)
writeLines(readLines(tmp, encoding = "UTF-8"))
#
#
#
#
# Table 3.2
# IRIS Sample Report
#
# Sepal Petal
# ------------ ------------
# Species Length Width Length Width
# -------------------------------------
# setosa 5.0 3.0 1.6 0.2
# 4.6 3.4 1.4 0.3
# 5.0 3.4 1.6 0.4
# 5.7 3.8 1.7 0.3
#
# versicolor 5.7 2.8 4.1 1.3
# 6.2 2.9 4.3 1.3
# 7.0 3.2 4.7 1.4
# 6.6 2.9 4.6 1.3
#
# virginica 6.2 3.4 5.4 2.3
# 7.2 3.0 5.8 1.6
# 6.9 3.1 5.1 2.3
# 5.6 2.8 4.9 2.0
# 7.7 2.6 6.9 2.3
# 6.3 2.8 5.1 1.5
# 7.7 2.8 6.7 2.0
#
#
# * From Fisher's Iris Dataset
Run the code above in your browser using DataLab