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' (< https://github.com/ActiveState/appdirs>) to R.


rappdirs

R-CMD-check Codecov testcoverage

rappdirs is a port of appdirs to R. It lets you find the appropriate directory to save caches, logs, and data, on Linux, Mac, and Windows. It allows you to store files that need to shared across R sessions in a way that aligns with the CRAN policies.

Motivation

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>

Installation

Stable version:

install.packages("rappdirs")

Development version:

pak::pak("r-lib/rappdirs")

Usage

This kind of thing is what rappdirs is for. rappdirs 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())

For example, on Mac:

library(rappdirs)
appname <- "SuperApp"
appauthor <- "Acme"
user_config_dir(appname, appauthor)
#> [1] "~/Library/Application Support/SuperApp"
user_data_dir(appname, appauthor)
#> [1] "~/Library/Application Support/SuperApp"
site_data_dir(appname, appauthor)
#> [1] "/Library/Application Support/SuperApp"
user_cache_dir(appname, appauthor)
#> [1] "~/Library/Caches/SuperApp"
user_log_dir(appname, appauthor)
#> [1] "~/Library/Logs/SuperApp"

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rappdirs")

0.3.4 by Hadley Wickham, 9 months ago


https://rappdirs.r-lib.org, https://github.com/r-lib/rappdirs


Report a bug at https://github.com/r-lib/rappdirs/issues


Browse source code at https://github.com/cran/rappdirs


Authors: Hadley Wickham [trl, cre, cph] , Sridhar Ratnakumar [aut] , Trent Mick [aut] , ActiveState [cph] (R/appdir.r , R/cache.r , R/data.r , R/log.r translated from appdirs) , Eddy Petrisor [ctb] , Trevor Davis [trl, aut] (ORCID: , Gabor Csardi [ctb] , Gregory Jefferis [ctb] , Posit Software , PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>)


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests covr, roxygen2, testthat, withr


Imported by AMAPVox, AzureAuth, BIOMASS, CatastRo, ECOTOXr, LAGOSNE, Nmisc, TCRconvertR, TR8, VertexWiseR, addinslist, adklakedata, alarmdata, askgpt, batchtools, bcmaps, beastier, beautier, binman, blockr.io, ceramic, childeswordfreq, climaemet, clinspacy, comtradr, convertid, cookiemonster, coreheat, cvdprevent, designer, dlr, emburden, epidatr, eq5dsuite, eurostat, exifr, f1dataR, ffscrapr, fluidsynth, froggeR, gargle, geodata, giscoR, gmailr, gooseR, graph4lg, guildai, hoardr, hydrodownloadR, iai, icons, insee, jmastats, jmvconnect, labNorm, land4health, leaf, learnr, liteq, lulab.utils, mapSpain, measurementProtocol, mhcnuggetsr, mmstat4, multilinguer, nat.templatebrains, netmhc2pan, nflreadr, nhdR, nodeSub, onetime, opencpu, pandoc, pins, pkgcheck, pkgfilecache, puremoe, pureseqtmr, qgisprocess, rMIDAS, racademyocean, rappleads, rbedrock, rdhs, reticulate, rgoogleads, rhub, rirods, rlinkedinads, roam, rpymat, rstudio.prefs, rtiktokads, sass, seekr, selenium, settingsSync, shelter, shinyelectron, shinylive, sprtt, sqlhelper, staninside, tesseract, textdata, thematic, tidyhydat, tidymedia, tigris, togglr, torchvision, tsibbledata, usethis, verifyr2, virtuoso, wdpar, whep, yulab.utils.

Suggested by JuliaCall, STATcubeR, VectrixDB, babette, bdc, brapiR2, bslib, diffwrap, httr2, leafwax, mcbette, mlr, mongolstats, natmanager, nomisdata, pkgmatch, rpact, sentiment.ai, tinytiger, tracerer.


See at CRAN