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”
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
library(dplyr)
data1 <- tibble(
staff = c("andrey", "andrey", "anne", "john"),
amount = c(200, NA, 678, 233),
category = c("A", "B", "C", "A"))
r params$category
data1 |>
filter(staff == params$staff, category == params$category)