I am generating a number of reports using an RMarkdown script. I would like to add a custom header/footer to the word-document output using a parameter, e.g. client_name. When I render the RMarkdown from a separate script, it loops through the list of clients and changes the data. I would like the header to update as well.
I have tried the answers from this question with no luck, as well as used a word reference document to set the header. However with the reference document, I can only set a static header that is not updated when the parameter changes.
Header should show:
Steve
August 06, 2021
Page X of 3
With "Steve" updated to a different name upon looping.
Here's what I have in my YAML:
---
title: "test doc"
author:
- Author 1
- Author 2
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
word_document:
reference_docx: test1.docx
params:
client: "Steve"
header-includes:
- \usepackage{fancyhdr}
- \usepackage{lipsum}
- \pagestyle{fancy}
- \fancyhead[LE,L0]{"params$client <br> `r format(Sys.time(), '%B %d, %Y')` <br> Page \thepage of 3"}
always_allow_html: true
---