1

This has partially been asked (without any takers) here and I have reached out via comment here - apologies for the multi-pronged approach ...

In my ongoing quest (see here for the example and further aspects) to automated report assembly using bookdown, I would like to do the following:

  1. Start a paragraph in the yaml header like so:

    ---
    title: "Test Doc"
    author: "Balin"
    date: "May 29, 2018"
    abstract: "Bare bones abstract."
    output: 
      bookdown::pdf_document2:
        toc: no
    ---
    
    This stands in for an extensive report where `code`, its 
    documentation and interpretation of its results are integrated:
    
    1. We load some data:
       ```{r data-loading}
        my_data <- cars
        # PLACEHOLDER (see in text below) #
       ```
    <!-- ... -->
    
  2. As the processing progresses I aim to edit the yaml-deriving abstract, cumulatively assembling/augmenting it. I know about rmarkdown::metadata$abstract (see e.g. here), but the metadata object appears immutable and can't be edited.

    I in essence want to replace the PLACEHOLDER bit in the example with something like:

    rmarkdown::metadata$abstract <- paste(
      rmarkdown::metadata$abstract,
      "The analyzed dataset contains",
      nrow(my_data),
      "data points.")
    

    Can that be achieved?

balin
  • 1,554
  • 1
  • 12
  • 26

1 Answers1

1

Remember that the YAML doesn't have to be all in one block, or all at the beginning of your Rmarkdown document.

In my Rmarkdown reports I put the abstract in a separate YAML block after the analysis. At that point you can reference R objects as inline expressions as in other Rmarkdown. The abstract will still be placed a the beginning of the output document.

```{r last_chunk}
# run R code
````

---
abstract: |
On `r Sys.Date()` we analyzed `r nrow(mydata)` observations and found...
----

The only trick - you must have empty lines before and after the --- delimiters for the YAML block to be recognized.

Caveat - I use this in Rmarkdown but haven't tested it with bookdown.

DonJ
  • 923
  • 11
  • 18