rappdirs v0.3.1

0

Monthly downloads

0th

Percentile

by Hadley Wickham

Application Directories: Determine Where to Save Data, Caches, and Logs

An easy way to determine which directories on the users computer you should use to save data, caches and logs. A port of Python's 'Appdirs' (\url{https://github.com/ActiveState/appdirs}) to R.

Readme

Build Status

rappdirs is a port of appdirs to R.

The problem

What directory should your app use for storing user data? If running on Mac OS X, you should use:

~/Library/Application Support/<AppName>

If on Windows (at least English Win XP) that should be:

C:\Documents and Settings\<User>\Application Data\Local Settings\<AppAuthor>\<AppName>

or possibly:

C:\Documents and Settings\<User>\Application Data\<AppAuthor>\<AppName>

for roaming profiles but that is another story.

On Linux (and other Unices) the dir, according to the XDG spec (and subject to some interpretation), is either:

~/.config/<AppName>     

or possibly:

~/.local/share/<AppName>

rappdirs to the rescue

This kind of thing is what the appdirs module is for. appdirs will help you choose an appropriate:

  • user data dir (user_data_dir)
  • user config dir (user_config_dir)
  • user cache dir (user_cache_dir)
  • site data dir (site_data_dir)
  • user log dir (user_log_dir)

and also:

  • is slightly opinionated on the directory names used. Look for 'Opinion' in documentation and code for when an opinion is being applied.

some example output

On Mac OS X:

library(appdirs)
appname <- "SuperApp"
appauthor <- "Acme"
user_config_dir(appname, appauthor)
# "/Users/trentm/Library/Application Support/SuperApp"
user_data_dir(appname, appauthor)
# "/Users/trentm/Library/Application Support/SuperApp"
site_data_dir(appname, appauthor)
# "/Library/Application Support/SuperApp"
user_cache_dir(appname, appauthor)
"/Users/trentm/Library/Caches/SuperApp"
user_log_dir(appname, appauthor)
"/Users/trentm/Library/Logs/SuperApp"

On Windows 7:

library(appdirs)
appname <- "SuperApp"
appauthor <- "Acme"
user_config_dir(appname, appauthor)
# "C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp"
user_data_dir(appname, appauthor)
# "C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp"
user_data_dir(appname, appauthor, roaming=True)
# "C:\\Users\\trentm\\AppData\\Roaming\\Acme\\SuperApp"
user_cache_dir(appname, appauthor)
# "C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp\\Cache"
user_log_dir(appname, appauthor)
# "C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp\\Logs"

On Linux:

library(appdirs)
appname <- "SuperApp"
appauthor <- "Acme"
user_config_dir(appname, appauthor)
# "/home/trentm/.config/SuperApp
user_data_dir(appname, appauthor)
# "/home/trentm/.local/share/SuperApp
site_config_dir(appname, appauthor)
# "/etc/xdg/SuperApp"
user_cache_dir(appname, appauthor)
# "/home/trentm/.cache/SuperApp"
user_log_dir(appname, appauthor)
# "/home/trentm/.cache/SuperApp/log"

app_dir for convenience

library(appdirs)
dirs <- app_dir("SuperApp", "Acme")
dirs$config()
# "/Users/trentm/Library/Application Support/SuperApp"
dirs$data()
# "/Users/trentm/Library/Application Support/SuperApp"
dirs$site_data()
# "/Library/Application Support/SuperApp"
dirs$cache()
# "/Users/trentm/Library/Caches/SuperApp"
dirs$log()
# "/Users/trentm/Library/Logs/SuperApp"

Per-version isolation

If you have multiple versions of your app in use that you want to be able to run side-by-side, then you may want version-isolation for these dirs:

library(appdirs)
dirs <- app_dir("SuperApp", "Acme", version = "1.0")
dirs$data()
# "/Users/trentm/Library/Application Support/SuperApp/1.0"
dirs$site_data()
# "/Library/Application Support/SuperApp/1.0"
dirs$cache()
# "/Users/trentm/Library/Caches/SuperApp/1.0"
dirs$log()
# "/Users/trentm/Library/Logs/SuperApp/1.0"

If you set the argument expand = TRUE (the default) you can have directories that correspond to R versions:

user_config_dir("R", version="%p-platform/%v")
# "/home/trevorld/.config/R/x86_64-pc-linux-gnu-platform/3.0"

Functions in rappdirs

Name Description
user_log_dir Return full path to the user-specific log dir for this application.
user_data_dir Return path to user data directories.
site_data_dir Return full path to the user-shared data dir for this application.
rappdirs-package Application directories: determine where to save data, caches and logs.
app_dir Convenience wrapper for getting app dirs.
user_cache_dir Return full path to the user-specific cache dir for this application.
No Results!

Last month downloads

Details

Type Package
BugReports https://github.com/hadley/rappdirs/issues
URL https://github.com/hadley/rappdirs https://github.com/ActiveState/appdirs
License MIT + file LICENSE
Copyright Original python appdirs module copyright (c) 2010 ActiveState Software Inc. R port copyright Hadley Wickham, RStudio. See file LICENSE for details.
RoxygenNote 5.0.1
NeedsCompilation yes
Packaged 2016-03-28 19:04:15 UTC; hadley
Repository CRAN
Date/Publication 2016-03-28 23:10:10

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/rappdirs)](http://www.rdocumentation.org/packages/rappdirs)