I'm hoping to use pkgdown to generate analysis websites and would like to use a large object in multiple site articles without either re-computing or saving a .Rda
file to include with the package build (i.e., data/x.Rda
).
By default, pkgdown::build_site()
ignores files in the vignettes
subdirectory with preceding underscores. My current approach uses a file vignettes/articles.Rmd
to perform some calculations that generate a large object, then renders additional .html
files using this global object via calls to rmarkdown::render()
. The contents of the .Rmd
look something like this:
---
title: "Render Articles"
---
Would like to be able to share `x` with reports and maintain pkgdown html.
```{r}
x <- runif(n = 10000000) # Some calculations that generate a large object
```
Global object `x` is available from `_QC1.Rmd`
```{r}
# Code chunk to generate report (repeated for multiple _*.Rmd files)
rmarkdown::render(
input = "_QC1.Rmd", # pkgdown::build_site() ignores files with preceding underscore
output_file = "QC1.html" # renders HTML file output without "_"; copied to docs/articles/
)
```
The _pkgdown.yml
can be modified to pickup the html files rendered from the Rmarkdown reports, but they lose the site formatting that is automated for other .Rmd
files by pkgdown::build_site()
.
I'd like to include the pkgdown site html formatting (i.e., title and site navbar) in these Rmarkdown reports if possible.
_pkgdown.yml
contents:
navbar:
title: ~
left:
- text: QC
menu:
- text: QC1
href: articles/QC1.html
- text: QC2
href: articles/QC2.html
I'm unsure if there is a better way for sharing an object across articles (though I understand these are typically self-contained). This approach works, but the html pages rendered for the Rmarkdown reports lose pkgdown formatting which drops the site navbar.
# Example of package vignettes subdirectory contents
1 vignettes
2 ¦--_QC1.Rmd # ignored by pkgdown::build_site()
3 ¦--_QC2.Rmd
4 ¦--articles.html
5 ¦--articles.Rmd # contains R chunks for rendering Rmarkdown reports
6 ¦--QC1.html # picked up in _pkgdown.yml from `docs/articles/`
7 °--QC2.html
Edit: Will look into the source code here:
https://github.com/r-lib/pkgdown/blob/master/R/build-articles.R