RMarkdown report to Word with parameterized results chapters
I am creating a report in RMarkdown that will consist of some introduction material, then several chapters whose content repeats for each of a set of species. I have to knit the final product to Word. I am aware that this is kind of annoying. Sorry! I must for this task.
So far, my best approach for this has been to render one .docx for the introduction material, then one .docx for each chapter, using a parameterized Rmd file. Each of the chapters contains figures and tables. However, when I combine all the Word docs with the chapters at the end of the document, the indices in the Figure and Table captions update properly (i.e., the figure numbers are sequential from the start), but the in-text citations refer back to chapter 1's figures over and over. I think this is because the parameterized document retains the chapter 1 tag in later chapters (below is what pops up when I right click on an in-text citation label and look at the labels:
Maybe a new approach?
I have vacillated between trying child documents, using eval(parse(
type statements in r, and this current approach, and I think parameterized reports suit my needs the best, but truly... I will try anything.
To recreate the situation
I have created a repo with a toy example of this here.
- Clone the repo
- Run the
run.R
script - in Word, insert the two ParameterizedChapter*.docx chapters into Word using Insert--> Object-->Text from file
- Update all the fields in the doc (in Windows this is Ctl-A and then F9.
Thank you in advance for your help!