library(reporter)
library(magrittr)
# Create a temporary file
tmp <- file.path(tempdir(), "expenses.txt")
# Prepare data
dat <- data.frame(category = rownames(USPersonalExpenditure),
USPersonalExpenditure, stringsAsFactors = FALSE)
# Define table
tbl <- create_table(dat) %>%
titles("Table 1.0", "US Personal Expenditures from 1940 - 1960") %>%
column_defaults(from = X1940, to = X1960, width = .6, format = "$%.2f") %>%
define(category, label = "Category") %>%
define(X1940, label = "1940") %>%
define(X1945, label = "1945") %>%
define(X1950, label = "1950") %>%
define(X1955, label = "1955") %>%
define(X1960, label = "1960") %>%
footnotes("* In billions of dollars")
# Define report
rpt <- create_report(tmp, orientation="portrait") %>%
add_content(tbl)
# Write the report
write_report(rpt)
# Display in console
writeLines(readLines(tmp, encoding = "UTF-8"))
# Table 1.0
# US Personal Expenditures from 1940 - 1960
#
# Category 1940 1945 1950 1955 1960
# ------------------------------------------------------------
# Food and Tobacco $22.20 $44.50 $59.60 $73.20 $86.80
# Household Operation $10.50 $15.50 $29.00 $36.50 $46.20
# Medical and Health $3.53 $5.76 $9.71 $14.00 $21.10
# Personal Care $1.04 $1.98 $2.45 $3.40 $5.40
# Private Education $0.34 $0.97 $1.80 $2.60 $3.64
#
# * In billions of dollars
Run the code above in your browser using DataLab