If package=='datarepository' then the path to the data repository is appended with the specified file(s).

system.file(..., package = "base", lib.loc = NULL, mustWork = FALSE)

Arguments

...

character vectors, specifying subdirectory and file(s) within some package. The default, none, returns the root of the package. Wildcards are not supported.

package

a character string with the name of a single package. An error occurs if more than one package name is given.

lib.loc

a character vector with path names of R libraries. See ‘Details’ for the meaning of the default value of NULL.

mustWork

logical. If TRUE, an error is given if there are no matching files.

Value

A path to the file(s) specified that exist, as base::system.file()

Details

This checks the existence of the specified files with file.exists. So file paths are only returned if there are sufficient permissions to establish their existence.

The unnamed arguments in ... are usually character strings, but if character vectors they are recycled to the same length.

This uses find.package to find the package, and hence with the default lib.loc = NULL looks first for attached packages then in each library listed in .libPaths(). Note that if a namespace is loaded but the package is not attached, this will look only on .libPaths().

See also

base::system.file

Examples

system.file() # The root of the 'base' package
#> [1] "/Library/Frameworks/R.framework/Resources/library/base"
system.file(package = "stats") # The root of package 'stats'
#> [1] "/Library/Frameworks/R.framework/Resources/library/stats"
system.file("INDEX")
#> [1] "/Library/Frameworks/R.framework/Resources/library/base/INDEX"
system.file("help", "AnIndex", package = "splines")
#> [1] "/Library/Frameworks/R.framework/Resources/library/splines/help/AnIndex"