R_user_dir
R User Directories

Description

Provides suggested paths for storing package related data, configuration, and cache files.

Usage

R_user_dir(package, which = c("data", "config", "cache"))

Arguments

package The name of a package
which One of "data", "config", or "cache" specifying which sort of user- and package-specific directory is desired.

Details

Some packages need to store data or configuration information created after the package is installed and based on a user's preferences. That data can be stored "permanently" in the data or config directories named by this function. Also, for performance reasons, some packages want to store data which takes a long time to compute but can be recomputed without user intervention if the data is lost. That data should be stored in the cache directory.
On Windows the "data" and "config" directories will be under file.path(Sys.getenv("APPDATA"), "TERR") and the "cache" directory will be under file.path(Sys.getenv("LOCALAPPDATA"), "TERR"). On Linux the "data" directory will be under file.path(Sys.getenv("HOME"), ".local", "share", "TERR"), the "config" directory will be under file.path(Sys.getenv("HOME"), ".config", "TERR"), and the "cache" directory will be under file.path(Sys.getenv("HOME"), ".cache", "TERR"). On the Mac, these directories will be under file.path(Sys.getenv("HOME"), "Library"), in the subdirectories "Application Support", "Preferences", and "Caches". These default locations can be overridden by setting the environment variables "TERR_USER_which_DIR", "R_USER_which_DIR", and "XDG_which_HOME" where "which" is one of "DATA", "CONFIG", and "CACHE". The first of those variables set to a non-blank value will be used.
This function will not create the directory; use dir.create(directory, recursive=TRUE) to make it.
This functions should generally be called from a package, not directly by the user.
Value
The name of user- and package-specific directory, which may or may not exist.
Examples
tools::R_user_dir("somePackage", which="config")
## Not run: 
configDir <- tools::R_user_dir("somePackage", which="config")
if (!dir.exists(configDir)) {
    dir.create(configDir, recursive=TRUE)
}
configFile <- file.path(configDir, "Startup.dcf")
prevConfigInfo <- tryCatch(
    read.dcf(configFile),
    error = function(e) matrix(character(), nrow=1, ncol=0))
write.dcf(file=configFile, cbind(prevConfigInfo, Debug="FALSE", Args="--flag-A"))

## End(Not run)
Package tools version 6.1.4-13
Package Index