I have adata frame in R called data and looks like this :
library(tibble)
library(flextable)
library(dplyr)
# Create a tibble
data <- tibble(
country = c("USA", "Canada", "Germany", "France", "Japan", "USA", "USA", "Germany"),
project = c("Project A", "Project B", "Project C", "Project D", "Project E", "Project F", "Project G", "Project H"),
val1 = c(10, 20, 30, 40, 50, 60, 70, 80),
val2 = c(15, 25, 35, 45, 55, 65, 75, 85),
val3 = c(12, 22, 32, 42, 52, 62, 72, 82)
)
> data
# A tibble: 8 × 5
country project val1 val2 val3
<chr> <chr> <dbl> <dbl> <dbl>
1 USA Project A 10 15 12
2 Canada Project B 20 25 22
3 Germany Project C 30 35 32
4 France Project D 40 45 42
5 Japan Project E 50 55 52
6 USA Project F 60 65 62
7 USA Project G 70 75 72
8 Germany Project H 80 85 82
i want to do some basic calculations and then show in different pages in a pdf each project table .
My effort is :
flextables_list = data %>%
rowwise() %>%
mutate(mean_val = mean(c_across(val1:val3))) %>%
group_split(project) %>%
lapply(function(project_data) {
flextable::flextable(project_data[, c("project", "country", "mean_val")])
})
and then print them in order to show them :
for (tbl in flextables_list) {
print(tbl)
}
but when I render the rmarkdown to pdf the tables (flextables) do not show. Why ?
Any help ?