I'm facing the following challenge: I have a long report with repeated sections (chunks) where I use the same chunk format and functions for generating plots/ tables, but they need to use a different value if 'i' (as a parameter) to select a different variable to generate all that for.
The solutions I've tried so far:
ref.label= - as a chunk option where I refer a chunk before. That would generally work but as far as I know there is no possibility to somehow pass a parameter such as: i <- 2, i <- 3 in order to make the chunk render for a different variable right?
child= - to reference an external Rmd file. I was thinking that I could have a universal script where the name of the file carries the parameter value, such as: Chunk_1.Rmd, and then within the file itself I have an element that tries to read the file name and subset the parameter that is then further carried across the file to generate content such as:
i <- sys.frame(1)$ofile i <- as.numeric(str_sub(i$value, 7, 7))
I would then have another script that would populate this file as many times with a different parameter value in the title as many variables as I have for the analysis. I would like to have this workflow set up like this because whenever I need to make a change in the general format the script would just populate all the inputs automatically. However this solution doesn't seem to work for Rmd files.
So at the moment I'm stuck with this looking for a good solution. Any of you faced a similar challenge?