library(reporter)
library(magrittr)
# Create temp file path
tmp <- file.path(tempdir(), "airquality.txt")
# Prepare Data
dat <- airquality[sample(1:153, 15), ]
dat$Month <- as.Date(paste0("1973-", dat$Month, "-01"))
# Define table
tbl <- create_table(dat, show_cols = c("Month", "Day", "Wind", "Temp", "Ozone")) %>%
titles("Table 9.6", "Air Quality Sample Report") %>%
column_defaults(width = .5) %>%
define(Month, format = "%B", align = "left", width = 1) %>%
define(Temp, format = "%.0f") %>%
footnotes("* New York, May to September 1973")
# Define report
rpt <- create_report(tmp, orientation = "portrait", missing = "-") %>%
add_content(tbl)
# Write the report to the file system
write_report(rpt)
# Write the report to the console
writeLines(readLines(tmp, encoding = "UTF-8"))
# Table 9.6
# Air Quality Sample Report
#
# Month Day Wind Temp Ozone
# ----------------------------------------
# July 8 6.3 92 97
# July 9 5.7 92 97
# August 1 6.9 81 39
# July 23 11.5 82 -
# June 9 13.8 90 71
# July 12 14.3 73 10
# July 4 10.9 84 -
# May 31 7.4 76 37
# September 30 11.5 68 20
# June 25 8 75 -
# June 28 11.5 80 -
# August 18 7.4 76 23
# June 20 10.3 76 13
# July 1 4.1 84 135
# May 23 9.7 61 4
#
# * New York, May to September 1973
Run the code above in your browser using DataLab