7.3.1 Filepaths

If you want to list the data files distributed with a package, can use system.file(). For example:

system.file("extdata", package = "readxl") |> list.files()
#>  [1] "clippy.xls"    "clippy.xlsx"   "datasets.xls"  "datasets.xlsx"
#>  [5] "deaths.xls"    "deaths.xlsx"   "geometry.xls"  "geometry.xlsx"
#>  [9] "type-me.xls"   "type-me.xlsx"

However, since the file path changes when the package is installed, the file path will be different for you vs. for the user of the package.

But! Using devtools::load_all() will make calls to system.file() just work.

Can also use fs::path_package().

? I don’t quite understand when/why we would want to use file paths like this.