One of the features that we added to the most recent release of Inference is the ability to print Expression output to the header and footer regions of Microsoft Word documents. I recently created a sample How-To Guide that illustrates dynamic header and footer output in an Inference in Word document. If you have Inference for R installed, you can download the How-To Guide, entitled "Header and Footer Output in Word," from Inference Online:
To print output to headers and footers:
- Create an Expression that returns a value.
- Enter a Label for the Expression – for example, MyExpression.
- In a header or footer, type the Label of the Expression (enclosed in greater than/less than brackets). Example: <MyExpression>.
When the document is executed, the bracketed Expression label placeholders will be replaced with the actual code output from the Expression.
Here are some additional tips:
- You can use the Output Result property of the Expression to specify whether the Expression gets evaluated in the Word canvas during document execution. This restricts the expression output to only the header or footer.
- You can use the Alias Code Text property of the Expression to specify whether the code, or the label, is shown in the Word canvas for an Expression. This makes the Word canvas easier to read.
- If your document includes a Data Frame, you can use an Expression to access its attributes. For example, if your DataFrame includes a title or version number, you can include that in the header/footer of your results document.
- Header/footer output will also be included in pdf results documents.
- This same functionality also works in Excel.
In the actual How-To Guide, we create two Expressions that will generate the header and footer output, and then add the placeholders into the header and footer areas of the document:
When the document is executed to a Microsoft Word View, the Expressions are evaluated, and their output replaces those placeholders in the header and footer sections:
That's pretty much it. You can download this How-To Guide from Inference Online and try it out yourself!