How to write an article with abstract reference data that has not yet been calculated?

UPDATE: it seems my question is actually a very close duplicate of this question and there is currently no “easy” solution to this thread. However, this issue has been around for more than a year, and time may change (hopefully!).

My initial question is:


I think I need some mechanism to reorder the text and Rpieces in the document, as it knits. What I want to do is to write an “article” style document with an abstract and summary description at the beginning, before I get into any code R, but which contains “forward” links to things that will be calculated in the code R.

So my resume at the beginning may be

We found a `r final_correlation / 100`% correlation between x and y ...
but "final_correlation" will be calculated at the end of the document when I go through all the steps of the reproduced study.

In fact, when I read about reproducible research, I often see comments that documentation can often be better represented outside the programming sequence.

I believe that in other literate programming systems, pieces can be confused in a different order from the one in which they were presented. How can I achieve this in knitr? Or is there some other completely different workflow or template that I could take to achieve the desired result?

+4
1

knitr . , , - . :

  • article.Rmd
  • abstract.Rmd

article.Rmd:

Title.

Author.

Abstract.

```{r echo=FALSE, results='asis'}
if (file.exists('abstract.md')) {
  cat(readLines('abstract.md'), sep = '\n')
} else {
  cat('Abstract not ready yet.')
}
```

More code chunks.

```{r}
x <- 1:10
y <- rnorm(10)
final_correlation <- cor(x, y)
```

Body.

```{r include=FALSE}
knitr::knit('abstract.Rmd')  # generates abstract.md
```

abstract.Rmd:

We found a `r final_correlation/100`% correlation between x and y...
+1

All Articles