【发布时间】:2017-09-28 05:18:33
【问题描述】:
我对 RMarkdown 非常陌生,我正在尝试使用来自数据框的地图生成单独的 pdf 报告,但输出是基于给出的特定答案的评估问题和建议的形式。我试图寻找一些例子来帮助无济于事。
这是我正在使用的数据框的一个子集,如下所示
mill_name latitude longitude theme section question remark
<chr> <dbl> <dbl> <chr> <dbl> <chr> <chr>
1 Mill A 3.955042 102.7211 environment 1.1 Do you have issue 1 in your area? Refer to Guideline 1
2 Mill A 3.955042 102.7211 environment 1.2 Do you have issue 2 in your area? Refer to Guideline 2
3 Mill A 3.955042 102.7211 social 1.3 Do you have issue 3 in your area? Refer to Guideline 3
4 Mill A 3.955042 102.7211 social 1.4 Do you have issue 4 in your area? Refer to Guideline 4
5 Mill B 1.961030 103.4140 environment 1.1 Do you have issue 1 in your area? Refer to Guideline 1
6 Mill B 1.961030 103.4140 environment 1.2 Do you have issue 2 in your area? Refer to Guideline 2
7 Mill B 1.961030 103.4140 social 1.3 Do you have issue 3 in your area? Refer to Guideline 3
8 Mill B 1.961030 103.4140 social 1.4 Do you have issue 4 in your area? Refer to Guideline 4
我从自己的研究中设法生成的 rmarkdown 代码如下所示
---
title: "Summary Report"
author: "Authors Name"
date: "September 19, 2015"
output: pdf_document
---
# Summary
This is a summary report for your mill
```{r, comment=NA, echo=FALSE}
# A table with data received from R script
# create reports on students from an Excel spreadsheet.
library(readxl)
library(knitr)
setwd("C:/Users/Jason/Mill Summary Report")
# read in the excel file
data <- read_excel("dummy_pat_results.xlsx")
for (i in 1:nrow(data)) {
cat("Section:", data$section[i], "\n")
cat("Question: ",data$question[i], "\n")
cat("Remark: ",data$remark[i], "\n")
cat("\n")
}
```
我使用的 R 脚本如下所示
library("rmarkdown")
for (i in unique(data$mill_name)){
subgroup <- data[data$mill_name == i,]
rmarkdown::render("Test_Markdown_v2.Rmd",
output_file=paste0(i, ".pdf"))
}
这就是我现在为我创建的 2 个 pdf 获得的内容,首先不是将它们分解为每个 Mill 的报告(Mill A 和 Mill B)
理想情况下,我想要的是这样的
我已经看到了许多为具有不同数据集的图创建单独报告的示例,但与我需要的报告完全不同。对此的任何帮助都非常感谢。提前致谢。
【问题讨论】:
-
看起来parameterized report 可能是您需要的。除了 RStudio 文档的链接之外,here is an SO answer 还提供了一个示例。
-
谢谢@eipi10 你提供的链接很有帮助!
标签: r pdf r-markdown