我正在尝试将数据框转换为带有参数列表的数据框,以发送到参数化降价报告。我正在遵循R Markdown: The Definitive Guide作为指导。
library(tidyr)
library(dplyr)
library(purrr)
master_list <- tibble(
client = rep(1:2, each = 3),
product = rep(LETTERS[1:3], 2),
price = abs(rnorm(6))*10,
quantity = round(runif(6)*100)
)
report_list <- master_list %>%
nest(-client) %>%
mutate(filename = paste0("Report for ", client, ".pdf"))
# paramaters for report
params <- report_list %>%
rowwise() %>%
do(params = as.list(.))
reports <- bind_cols(report_list, params)
# code to send to rmarkdown::render
reports %>%
select(output_file = filename, params) %>%
purrr::pwalk(rmarkdown::render, input = "./Rmd/subscriber-report.Rmd")
编辑:确实可以,但是我觉得构建报表数据框的过程很麻烦(再加上我真的不喜欢这些参数在rmd代码中具有额外的列表级别,可以不使用)。关于如何简化报表数据框架构建的任何想法?