userdir {tools}R Documentation

R User Directories


Directories for storing R-related user-specific data, configuration and cache files.


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



a character string giving the name of an R package


a character string indicating the kind of file(s) of interest. Can be abbreviated.


For desktop environments using X Windows, the project (formerly X Desktop Group, XDG) developed the XDG Base Directory Specification ( for standardizing the location where certain files should be placed. CRAN package rappdirs provides these general locations with appropriate values for all platforms for which R is available.

R_user_dir specializes the general mechanism to R package specific locations for user files, by providing package specific subdirectories inside a ‘R’ subdirectory inside the “base” directories appropriate for user-specific data, configuration and cache files (see the examples), with the intent that packages will not interfere if they work within their respective subdirectories.

The locations of these base directories can be customized via the specific environment variables R_USER_DATA_DIR, R_USER_CONFIG_DIR and R_USER_CACHE_DIR. If these are not set, the general XDG-style environment variables XDG_DATA_HOME, XDG_CONFIG_HOME and XDG_CACHE_HOME are used if set, and otherwise, defaults appropriate for the R platform in use are employed.


R_user_dir("FOO", "cache")

## Create one, platform agnostically, must work if <normal> :
(Rdb <- R_user_dir("base"))
if(newD <- !dir.exists(Rdb)) # should work user specifically:
    newD <- dir.create(Rdb, recursive=TRUE)
dir(Rdb) # typically empty
if(newD) unlink(Rdb) # cleaning up

list.files(R_user_dir("grid"), full.names = TRUE)

[Package tools version 4.4.1 Index]