I was just wondering if it is possible to loop over a r-notebook from an external r file?
My dataset contains a group variable "group" and I should generate a report for each of the 32 groups separately (plus one for the groups together).
My notebook looks basically like this:
dat <- read_spss(...)
dat %>% ...
... %>%
ggplot() %>%
ggsave(here::here("image1_grp1.png"))
dat %>% ...
... %>%
ggplot() %>%
ggsave(here::here("image2_grp1.png"))
...
Now, my idea was to simply filter the dataset on top of the r-notebook like this:
dat <- read_spss(...) %>%
filter(group == group)
and for the image filenames I would simply use ggsave(here::here(paste0("image",grp"2.png"))
But how can I run a notebook from an external r-script and pass the parameter grp
to the notebook?
groups <- unique(dat$group)
for(group in groups){
...execute notebook...?
}