system_file: Get a system file or directory

Description Usage Arguments Value Note See Also Examples

View source: R/system_file.R

Description

Get system files or directories, in R subdirectories, in package subdirectories, or elsewhere on the disk (including executables that are accessible on the search path).

Usage

1
2
3
4
5
6
7
system_file(..., exec = FALSE, package = NULL, lib.loc = NULL)

system_dir(..., exec = FALSE, package = NULL, lib.loc = NULL)

systemFile(..., exec = FALSE, package = NULL, lib.loc = NULL)

systemDir(..., exec = FALSE, package = NULL, lib.loc = NULL)

Arguments

...

One or several executables if exec = TRUE, or subpath to a file or dir in a package directory if package != NULL, or a list of paths and subpaths for testing the existence of a file on disk, or a list of directory components to retrieve in 'temp', 'sysTemp', 'user', 'home', 'bin', 'doc', 'etc' and/or 'share' to retrieve special system directories.

exec

If TRUE (default) search for executables on the search path. It supersedes all other arguments.

package

The name of one package to look for files or subdirs in its main directory (use exec = FALSE to search inside package dirs).

lib.loc

A character vector with path names of R libraries or NULL (search all currently known libraries in this case).

Value

A string with the path to the directories or files, or "" if they are not found, or of the wrong type (a dir for system_file() or or a file for system_dir()).

Note

These function aggregate the features of several R functions in package base: system.file(), R.home(), tempdir(), Sys.which(), and aims to provide a unified and convenient single interface to all of them. We make sure also to check that returned components are respectively directories and files for system_dir() and system_file().

See Also

file_edit(), file.path(), file.exists()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
system_file("INDEX", package = "base")
system_file("help", "AnIndex", package = "splines")
system_file(package = "base")  # This is a dir, not a file!
system_file("zip", exec = TRUE)
system_file("ftp", "ping", "zip", "nonexistingexe", exec = TRUE)
system_dir("temp")             # The R temporary directory
system_dir("sysTemp")          # The system temporary directory
system_dir("user")             # The user directory
system_dir("home", "bin", "doc", "etc", "share")  # Various R dirs
system_dir("zip", exec = TRUE) # Look for the dir of an executable
system_dir("ftp", "ping", "zip", "nonexistingexe", exec = TRUE)
system_dir(package = "base")   # The root of the 'base' package
system_dir(package = "stats")  # The root of package 'stats'
system_dir("INDEX", package = "stats") # This is a file, not a dir!
system_dir("help", package = "splines")

svMisc documentation built on Oct. 12, 2021, 1:08 a.m.