I would like to use categories in variable to create subsections in RMarkdown and display the results of each category in the given section….
This is the R script
library(rmarkdown)
library(dplyr)
data1 <- tibble(
staff = c("andrey", "andrey", "anne", "john"),
amount = c(200, NA, 678, 233),
category = c("A", "B", "C", "A")
)
lapply(unique(data1$staff), function(x) {
render("scripts/render_test.Rmd",
output_format = "pdf_document",
params = list(staff = x),
output_file = paste0(x, ".pdf"))
})
And below is the RMarkdown file
---
output: pdf_document
params:
staff: "andrey"
category: "A"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
```
```{r}
library(dplyr)
```
```{r}
data1 <- tibble(
staff = c("andrey", "andrey", "anne", "john"),
amount = c(200, NA, 678, 233),
category = c("A", "B", "C", "A"))
```
## `r params$category`
```{r}
data1 |>
filter(staff == params$staff, category == params$category)
```