17.6 Filepaths
Sometimes it is necessary to refer to another file from a vignette. The best way to do this depends on the application:
A figure created by code evaluated in the vignette: By default, in the .Rmd workflow that we recommend, this takes care of itself. Such figures are automatically embedded into the .html using data URIs. You don’t need to do anything. Example: vignette(“extending-ggplot2”, package = “ggplot2”) generates a few figures in evaluated code chunks.
An external file that could be useful to users or elsewhere in the package (not just in vignettes): Put such a file in inst/ (Section 9.3), perhaps in inst/extdata/ (Section 8.4), and refer to it with system.file() or fs::path_package() ( Section 8.4.1). Example from vignette(“sf2”, package = “sf”):
An external file whose utility is limited to your vignettes: put it alongside the vignette source files in vignettes/ and refer to it with a filepath that is relative to vignettes/.
An external graphics file: put it in vignettes/, refer to it with a filepath that is relative to vignettes/ and use knitr::include_graphics() inside a code chunk. Example from vignette(“sheet-geometry”, package = “readxl”):