@technocrat we are here with an issue with rmarkdown - template partials is a Quarto feature, so it won't apply here. We need a more scoped answer to the current question.
@Leprechault please to read again some "Getting Started' section about how R Markdown is working, and what a Rmd is. You have the Definitive Guide, and the R Markdown Cookbook to help you.
Here, you can't add some code chunks in the YAML header part. That can't work - YAML needs to be YAML.
So obviously this won't work at all.
Also you may find in those resources your solutions. Example this recipe: