4

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?

Michael Roswell
  • 1,300
  • 12
  • 31
  • 1
    Why don´t you store the bibfile in the vignettes folder? This works for my packages and you can just use `bibliography: REFERENCES.bib` in your YAML header. – J_F Dec 31 '20 at 13:52
  • Thanks @J_F! Does this cause any issues with including citations in the roxygen comments for your functions? I followed instructions for the package `Rdpack` which said to keep them in the `inst/` folder. https://geobosh.github.io/Rdpack/#org88fb0a7 – Michael Roswell Dec 31 '20 at 14:22

1 Answers1

4

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.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
Michael Roswell
  • 1,300
  • 12
  • 31
  • This does not really work for me. – jjmerelo Oct 01 '22 at 10:20
  • This didn't work for me either. I ended up copying the `REFERENCES.bib` file over to the vignettes folder, as suggested in a previous comment, and then added the following line to my YAML header: `bibliography: REFERENCES.bib`. I cited using `@key`, for example `@author_year`. – Ann Marie Weideman Jun 24 '23 at 20:51