rpackageknitrvignette

How to include inst/REFERENCES.bib in vignette


Running devtools::check() on my computer I can force my package to build without error using an absolute path to my .bib file. But since I included all my citations in the package vignette and tried to point to the .bib file that contains all the bibtex references, I have not yet gotten the package to build with GitHub Actions (where that absolute path makes no sense). I am seeking advice on how to point to the .bib file in the vignette's YAML header.

The location of the .bib file in the inst/ directory allows me to use the citations in the .Rd documentation for the package (as suggested here: https://geobosh.github.io/Rdpack/#org88fb0a7), so I am mostly interested in solutions that let me reference the file in that location rather than keeping it in an alternate directory.

My YAML header reads:

---
title: "Using_my_package"
output: rmarkdown::html_vignette
bibliography: "where/I/keep/my/package/inst/REFERENCES.bib"
latex_engine: xelatex
vignette: >
  %\VignetteIndexEntry{Using_my_package}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
  %\SweaveUTF8
  
---

I also tried

 bibliography: `'r system.file("inst", "REFERENCES.bib", package="mypackage")`'`

How can I use a relative path in the YAML header so that I can build the vignette from any location?


Solution

  • It appears the solution is to omit "inst" in the system.file call. Thanks to a comment from @Martin Morgan here. The working YAML header now reads

    bibliography: '`r system.file("REFERENCES.bib", package="mypackage")`'
    

    and the build succeeded on all systems with GitHub Actions as well as on my local machine.