Is there a way to pass a single yaml params list to several different rmd documents at once?

UPDATE: Solution found :grinning:

After additional research, I found Keenwrite, a java based cross platform editor with string interpolation built in, and it has R integration built in. Since my use case is rather simple — and since I'm certainly no programmer or data analyst — I think Keenwrite may be just what I've been looking for.


Hi everybody, here's my use case —

I have several related documents that all use the same placeholders, to be replaced by the same text. In my case, the text to replace includes things like client names, addresses, and so forth.

Ideally, I want to write a single yaml frontmatter with all the params defined, to replace the paramater placeholders in all of the separate documents.

The goal is to avoid having to re-write (or copy & paste) the yaml params list in the header of each separate document.

The reason I have to use separate documents is because:

  • I'm producing Word documents; and
  • there is presently no way to restart page numbering (from page 1) by section.

Despite several hours of research, I haven't found an answer. Any help the community can provide would be greatly appreciated.

For parameters, when you need to pass custom parameters and not use the default, you can pass them at rendering in rmarkdown::render() to change their value for a rendering, using the same Rmd file.

But I understand you are using different document but I am not sure to understand why: you can get one word per rendering using only one Rmd file ?

Also you document is acting as a template if I understand correctly ?
This means you could also use templating mechanism (whisker for example) to fill the template using data before rendering. Params are kind of doing the same thing but during rendering.

I don't think there is a way currently to share a YAML header for this params field. (you can for output field). You would need to write custom pre processing function to add the YAML part you need in a document before rendering. ymlthis package can help maybe

Hope it helps

1 Like

Solution found — see update to the original post above

Thank you for replying, the information you shared is helpful.

The reason I want to use several separate template documents is because each separate document needs its own separate page numbers. As described below, I believe there is no way to use a single template Rmd file to produce a Word document with several separate page numberings (each starting over from page 1).

In Word, I created a large, single template document that contains section breaks. Section breaks in Word allow a user to apply different page numbers within a single document. So, whenever I added a new document to the large template, I added a section break in front of it, and restarted the page numbering. The finished product is several separate documents, each with its own page numbers, from the single file.

While I hoped to be able to do the same in RStudio, it turns out this is not possible. According to officedown author David Gohel, Word section breaks are not recognized in Markdown. Officer and officedown are capable of allowing a user to apply complex style and formatting options to a docx template, but section breaks are not available.

I also looked at bookdown, but I was unable to find any tool that meets my need. As for latex, the best I could find was the possibility of up to three separate page numberings (TOC, main document, index?), but my templates contain 5 to 8 separate documents within a single file.

So, if there is no way for me to restart document page numbers within the same master template file, then my only other choice is to split up the template into its component document templates, pass the parameter value data to fill the placeholders within each template, and then render each template separately.

I'll look into whisker to see if I can get the same results with a single data set, but apply that same data to my several template files.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.