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:

library(sf)
fname <- system.file("shape/nc.shp", package="sf")
fname
nc <- st_read(fname)
  • 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”):