Include file from parent directory in pkgdown article

I currently a vignettes directory structured like so:

- vignettes
  - bib
    - references.bib
    - apa.csl
  - articles
    - article1.Rmd
    - article2.Rmd
  - vignette1.Rmd
  - vignette2.Rmd

So there are some vignettes that are built on CRAN, and some that are specific to the pkgdown website. All of the vignettes and articles use the vignettes/bib/references.bib and vignettes/bib/apa.csl files, and ideally, I would have just one copy of each file that can be referenced by all Rmd files (as in the current structure).

In the YAML of the articles, I have code like:

bibliography: ../bib/references.bib

When I build the pkgdown site locally, this works without issue. However, when the site attempts to build on GitHub actions, I get an error: File ../bib/apa.csl not found in resource path. Is there something special I need to do in order to be able to reference files in the articles YAML that are from a parent directory?

The full directory can be found here: https://github.com/wjakethompson/measr/tree/ecpe-case-study/vignettes

And the failed GitHub action: Add ECPE Case Study · wjakethompson/measr@f4ab389 · GitHub

I'd recommend creating a reproducible example of a smaller package.

For what it's worth, I can reproduce the error using simply pkgdown::build_articles():

Caused by error in `render_rmarkdown()`:
! Failed to render RMarkdown document.
✖ File ../../bib/apa.csl not found in resource path There were 12 warnings
  (use warnings() to see them)

An idea could be to store the bib file in inst/, see r - How to include inst/REFERENCES.bib in vignette - Stack Overflow

I've created a minimal example here: GitHub - wjakethompson/testpkgdown: For Testing Pkgdown Functionality

The inst directory did not work for me.

Interestingly, when I was creating the minimal example, I noticed that articles directly under articles (e.g., articles/article1.Rmd) rendered just fine with bibliography: ../bib/references.bib.
It was only when I added an extra level of nesting that things broke.

Here is the run that only included vignettes/vignette1.Rmd and vignettes/articles/article1.Rmd: add pkgdown · wjakethompson/testpkgdown@3ca98a1 · GitHub

When I also added vignettes/articels/nested-article/nested-article1.Rmd with bibliography: ../../bib/references.bib, that's when I get the resource not found error: try nested article · wjakethompson/testpkgdown@f237a9b · GitHub

why do you want to add a level of nesting, by the way?

It's not strictly necessary, but it just help keep me organized. There are only a few vignettes in the actual repo right now, but I'm planning to add several more. Originally, it made sense to me to keep the different types of articles in different folders (e.g., general purpose in the main articles directory, specific types of use cases in sub-directories). But if it's a choice between having a single .bib file or having subdirectories, I'd rather have a single .bib file :smiling_face:.

1 Like

This topic was automatically closed after 45 days. 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.