rappdirs/0000755000176200001440000000000014005441262012074 5ustar liggesusersrappdirs/NAMESPACE0000644000176200001440000000035614004633436013324 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(app_dir) export(site_config_dir) export(site_data_dir) export(user_cache_dir) export(user_config_dir) export(user_data_dir) export(user_log_dir) useDynLib(rappdirs, .registration=TRUE) rappdirs/LICENSE0000644000176200001440000000013212676277257013124 0ustar liggesusersYEAR: 2001, 2014-2016 COPYRIGHT HOLDER: Hadley Wickham; RStudio; ActiveState Software Inc rappdirs/README.md0000644000176200001440000000440414004633410013352 0ustar liggesusers # rappdirs [![R-CMD-check](https://github.com/r-lib/rappdirs/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/rappdirs/actions) [![CRAN status](https://www.r-pkg.org/badges/version/rappdirs)](https://CRAN.R-project.org/package=rappdirs) `rappdirs` is a port of [appdirs](https://github.com/ActiveState/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](https://cran.r-project.org/web/packages/policies.html). ## Motivation What directory should your app use for storing user data? If running on Mac OS X, you should use: ~/Library/Application Support/ If on Windows (at least English Win XP) that should be: C:\Documents and Settings\\Application Data\Local Settings\\ or possibly: C:\Documents and Settings\\Application Data\\ for [roaming profiles](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc766489(v=ws.10)) but that is another story. On Linux (and other Unices) the dir, according to the [XDG spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) (and subject to some interpretation), is either: ~/.config/ or possibly: ~/.local/share/ ## 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: ``` r 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" ``` rappdirs/man/0000755000176200001440000000000014004114402012637 5ustar liggesusersrappdirs/man/user_cache_dir.Rd0000644000176200001440000000460014004114402016065 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cache.r \name{user_cache_dir} \alias{user_cache_dir} \title{Path to user cache directory} \usage{ user_cache_dir( appname = NULL, appauthor = appname, version = NULL, opinion = TRUE, expand = TRUE, os = NULL ) } \arguments{ \item{appname}{is the name of application. If NULL, just the system directory is returned.} \item{appauthor}{(only required and used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname.} \item{version}{is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be \code{"."}. Only applied when appname is not NULL.} \item{opinion}{(logical) Use \code{FALSE} to disable the appending of \code{Cache} on Windows. See discussion below.} \item{expand}{If TRUE (the default) will expand the \code{R_LIBS} specifiers with their equivalents. See \code{\link[=R_LIBS]{R_LIBS()}} for list of all possibly specifiers.} \item{os}{Operating system whose conventions are used to construct the requested directory. Possible values are "win", "mac", "unix". If \code{NULL} (the default) then the current OS will be used.} } \description{ This functions uses \code{R_USER_CACHE_DIR} if set. Otherwise, they follow platform conventions. Typical user cache directories are: \itemize{ \item Mac OS X: \verb{~/Library/Caches/} \item Linux: \verb{~/.cache/} \item Win XP: \verb{C:\\\\Documents and Settings\\\\\\\\Local Settings\\\\Application Data\\\\\\\\\\\\Cache} \item Vista: \verb{C:\\\\Users\\\\\\\\AppData\\\\Local\\\\\\\\\\\\Cache} } } \section{Opinion}{ On Windows the only suggestion in the MSDN docs is that local settings go in the \code{CSIDL_LOCAL_APPDATA} directory. This is identical to the non-roaming app data dir (i.e. \code{\link[=user_data_dir]{user_data_dir()}}). But apps typically put cache data somewhere \emph{under} this directory so \code{user_cache_dir()} appends \code{Cache} to the \code{CSIDL_LOCAL_APPDATA} value, unless \code{opinion = FALSE}. } \examples{ user_cache_dir("rappdirs") } \seealso{ \code{\link[=tempdir]{tempdir()}} for a non-persistent temporary directory. } rappdirs/man/rappdirs-package.Rd0000644000176200001440000000274314004633254016364 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/rappdirs-package.r \docType{package} \name{rappdirs-package} \alias{rappdirs} \alias{rappdirs-package} \title{rappdirs: Application Directories: Determine Where to Save Data, Caches, and Logs} \description{ 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' () to R. } \section{Main functions}{ \itemize{ \item \code{\link[=user_data_dir]{user_data_dir()}} \item \code{\link[=user_config_dir]{user_config_dir()}} \item \code{\link[=user_cache_dir]{user_cache_dir()}} \item \code{\link[=site_data_dir]{site_data_dir()}} \item \code{\link[=user_log_dir]{user_log_dir()}} } } \seealso{ Useful links: \itemize{ \item \url{https://rappdirs.r-lib.org} \item \url{https://github.com/r-lib/rappdirs} \item Report bugs at \url{https://github.com/r-lib/rappdirs/issues} } } \author{ \strong{Maintainer}: Hadley Wickham \email{hadley@rstudio.com} [translator, copyright holder] Authors: \itemize{ \item Sridhar Ratnakumar \item Trent Mick \item Trevor Davis [translator] } Other contributors: \itemize{ \item RStudio [copyright holder] \item ActiveState (R/appdir.r, R/cache.r, R/data.r, R/log.r translated from appdirs) [copyright holder] \item Eddy Petrisor [contributor] \item Gabor Csardi [contributor] \item Gregory Jefferis [contributor] } } \keyword{internal} rappdirs/man/user_log_dir.Rd0000644000176200001440000000427314001364352015621 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/log.r \name{user_log_dir} \alias{user_log_dir} \title{Path to user log directory} \usage{ user_log_dir( appname = NULL, appauthor = appname, version = NULL, opinion = TRUE, expand = TRUE, os = NULL ) } \arguments{ \item{appname}{is the name of application. If NULL, just the system directory is returned.} \item{appauthor}{(only required and used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname.} \item{version}{is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be \code{"."}. Only applied when appname is not NULL.} \item{opinion}{(logical) can be \code{FALSE} to disable the appending of \file{Logs} to the base app data dir for Windows, and \file{log} to the base cache dir for Unix. See discussion below.} \item{expand}{If TRUE (the default) will expand the \code{R_LIBS} specifiers with their equivalents. See \code{\link[=R_LIBS]{R_LIBS()}} for list of all possibly specifiers.} \item{os}{Operating system whose conventions are used to construct the requested directory. Possible values are "win", "mac", "unix". If \code{NULL} (the default) then the current OS will be used.} } \description{ Typical user cache directories are: } \details{ \itemize{ \item Mac OS X: \file{~/Library/Logs/} \item Unix: \file{~/.cache//log}, or under \\env{$XDG_CACHE_HOME} if defined \item Win XP: \file{C:\\Documents and Settings\\\\Local Settings\\Application Data\\\\\\Logs} \item Vista: \file{C:\\Users\\\\AppData\\Local\\\\\\Logs} } On Windows the only suggestion in the MSDN docs is that local settings go in the \code{CSIDL_LOCAL_APPDATA} directory. } \section{Opinion}{ This function appends \file{Logs} to the \code{CSIDL_LOCAL_APPDATA} value for Windows and appends \file{log} to the user cache dir for Unix. This can be disabled with the \code{opinion = FALSE} option. } \examples{ user_log_dir() } rappdirs/man/app_dir.Rd0000644000176200001440000000312314001364034014550 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/appdir.r \name{app_dir} \alias{app_dir} \title{Record app information in a convenient object} \usage{ app_dir( appname = NULL, appauthor = appname, version = NULL, expand = TRUE, os = NULL ) } \arguments{ \item{appname}{is the name of application. If NULL, just the system directory is returned.} \item{appauthor}{(only required and used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname.} \item{version}{is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be \code{"."}. Only applied when appname is not NULL.} \item{expand}{If TRUE (the default) will expand the \code{R_LIBS} specifiers with their equivalents. See \code{\link[=R_LIBS]{R_LIBS()}} for list of all possibly specifiers.} \item{os}{Operating system whose conventions are used to construct the requested directory. Possible values are "win", "mac", "unix". If \code{NULL} (the default) then the current OS will be used.} } \description{ Has methods: \itemize{ \item \verb{$cache()} \item \verb{$log()} \item \verb{$data()} \item \verb{$config()} \item \verb{$site_data()} \item \verb{$site_config()} } } \examples{ ggplot2_app <- app_dir("ggplot2", "hadley") ggplot2_app$cache() ggplot2_app$log() ggplot2_app$data() ggplot2_app$config() ggplot2_app$site_config() ggplot2_app$site_data() } \keyword{internal} rappdirs/man/user_data_dir.Rd0000644000176200001440000000615314004114402015740 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.r \name{user_data_dir} \alias{user_data_dir} \alias{user_config_dir} \title{Path to user config/data directories} \usage{ user_data_dir( appname = NULL, appauthor = appname, version = NULL, roaming = FALSE, expand = TRUE, os = NULL ) user_config_dir( appname = NULL, appauthor = appname, version = NULL, roaming = TRUE, expand = TRUE, os = NULL ) } \arguments{ \item{appname}{is the name of application. If NULL, just the system directory is returned.} \item{appauthor}{(only required and used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname.} \item{version}{is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be \code{"."}. Only applied when appname is not NULL.} \item{roaming}{(logical, default \code{FALSE}) can be set \code{TRUE} to use the Windows roaming appdata directory. That means that for users on a Windows network setup for roaming profiles, this user data will be sync'd on login. See \url{https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc766489(v=ws.10)} for a discussion of issues.} \item{expand}{If TRUE (the default) will expand the \code{R_LIBS} specifiers with their equivalents. See \code{\link[=R_LIBS]{R_LIBS()}} for list of all possibly specifiers.} \item{os}{Operating system whose conventions are used to construct the requested directory. Possible values are "win", "mac", "unix". If \code{NULL} (the default) then the current OS will be used.} } \description{ \code{user_data_dir()} returns path to the user-specific data directory and \code{user_config_dir()} returns full path to the user-specific configuration directory. These are the same on Windows and Mac but different on Linux. These functions first use \code{R_USER_DATA_DIR} and \code{R_USER_CONFIG_DIR} if set. Otherwise, they follow platform conventions. Typical user config and data directories are: \itemize{ \item Mac OS X: \verb{~/Library/Application Support/} \item Win XP (not roaming): \verb{C:\\\\Documents and Settings\\\\\\\\Data\\\\\\\\} \item Win XP (roaming): \verb{C:\\\\Documents and Settings\\\\\\\\Local Settings\\\\Data\\\\\\\\} \item Win 7 (not roaming): \verb{C:\\\\Users\\\\\\\\AppData\\\\Local\\\\\\\\} \item Win 7 (roaming): \verb{C:\\\\Users\\\\\\\\AppData\\\\Roaming\\\\\\\\} } Only Linux makes the distinction between config and data: \itemize{ \item Data: \verb{~/.local/share/} \item Config: \verb{~/.config/} } } \examples{ user_data_dir("rappdirs") user_config_dir("rappdirs", roaming = TRUE, os = "win") user_config_dir("rappdirs", roaming = FALSE, os = "win") user_config_dir("rappdirs", os = "unix") user_config_dir("rappdirs", os = "mac") user_config_dir("rappdirs", version = "\%p-platform/\%v") } rappdirs/man/site_data_dir.Rd0000644000176200001440000000534514001364034015735 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/data.r \name{site_data_dir} \alias{site_data_dir} \alias{site_config_dir} \title{Path to shared data/config directories} \usage{ site_data_dir( appname = NULL, appauthor = appname, version = NULL, multipath = FALSE, expand = TRUE, os = NULL ) site_config_dir( appname = NULL, appauthor = appname, version = NULL, multipath = FALSE, expand = TRUE, os = NULL ) } \arguments{ \item{appname}{is the name of application. If NULL, just the system directory is returned.} \item{appauthor}{(only required and used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname.} \item{version}{is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be \code{"."}. Only applied when appname is not NULL.} \item{multipath}{is an optional parameter only applicable to *nix which indicates that the entire list of data dirs should be returned By default, the first directory is returned} \item{expand}{If TRUE (the default) will expand the \code{R_LIBS} specifiers with their equivalents. See \code{\link[=R_LIBS]{R_LIBS()}} for list of all possibly specifiers.} \item{os}{Operating system whose conventions are used to construct the requested directory. Possible values are "win", "mac", "unix". If \code{NULL} (the default) then the current OS will be used.} } \description{ \code{site_data_dir} returns full path to the user-shared data dir for this application. \code{site_config_dir} returns full path to the user-specific configuration directory for this application which returns the same path as site data directory in Windows and Mac but a different one for Unix. Typical user-shared data directories are: } \details{ \itemize{ \item Mac OS X: \verb{/Library/Application Support/} \item Unix: \verb{/usr/local/share:/usr/share/} \item Win XP: \verb{C:\\\\Documents and Settings\\\\All Users\\\\Application Data\\\\\\\\} \item Vista: (Fail! \verb{C:\\\\ProgramData} is a hidden \emph{system} directory on Vista.) \item Win 7: \verb{C:\\\\ProgramData\\\\\\\\}. Hidden, but writeable on Win 7. } Unix also specifies a separate location for user-shared configuration data in \env{$XDG_CONFIG_DIRS}. \itemize{ \item Unix: \verb{/etc/xdg/}, in \env{$XDG_CONFIG_HOME} if defined } For Unix, this returns the first default. Set the \code{multipath=TRUE} to guarantee returning all directories. } \section{Warning}{ Do not use this on Windows. See the note above for why. } rappdirs/DESCRIPTION0000644000176200001440000000424114005441262013603 0ustar liggesusersType: Package Package: rappdirs Title: Application Directories: Determine Where to Save Data, Caches, and Logs Version: 0.3.3 Authors@R: c(person(given = "Hadley", family = "Wickham", role = c("trl", "cre", "cph"), email = "hadley@rstudio.com"), person(given = "RStudio", role = "cph"), person(given = "Sridhar", family = "Ratnakumar", role = "aut"), person(given = "Trent", family = "Mick", role = "aut"), person(given = "ActiveState", role = "cph", comment = "R/appdir.r, R/cache.r, R/data.r, R/log.r translated from appdirs"), person(given = "Eddy", family = "Petrisor", role = "ctb"), person(given = "Trevor", family = "Davis", role = c("trl", "aut")), person(given = "Gabor", family = "Csardi", role = "ctb"), person(given = "Gregory", family = "Jefferis", role = "ctb")) Description: 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' () to R. License: MIT + file LICENSE URL: https://rappdirs.r-lib.org, https://github.com/r-lib/rappdirs BugReports: https://github.com/r-lib/rappdirs/issues Depends: R (>= 3.2) Suggests: roxygen2, testthat (>= 3.0.0), covr, withr Copyright: Original python appdirs module copyright (c) 2010 ActiveState Software Inc. R port copyright Hadley Wickham, RStudio. See file LICENSE for details. Encoding: UTF-8 RoxygenNote: 7.1.1 Config/testthat/edition: 3 NeedsCompilation: yes Packaged: 2021-01-28 22:29:57 UTC; hadley Author: Hadley Wickham [trl, cre, cph], RStudio [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], Gabor Csardi [ctb], Gregory Jefferis [ctb] Maintainer: Hadley Wickham Repository: CRAN Date/Publication: 2021-01-31 05:40:02 UTC rappdirs/tests/0000755000176200001440000000000014004114402013226 5ustar liggesusersrappdirs/tests/testthat/0000755000176200001440000000000014005441262015076 5ustar liggesusersrappdirs/tests/testthat/test-cache.r0000644000176200001440000000107114004114402017270 0ustar liggesuserstest_that("works on mac and linux", { withr::local_envvar(XDG_CACHE_HOME = NA) expect_equal(user_cache_dir("R", os = "unix"), "~/.cache/R") expect_equal(user_cache_dir("R", os = "mac"), "~/Library/Caches/R") }) test_that("can override with R_USER_CACHE_DIR", { withr::local_envvar(R_USER_CACHE_DIR = "/test") expect_equal(user_cache_dir("R", os = "mac"), "/test/R") }) test_that("works on windows simulation", { skip_on_os("windows") expect_equal( user_cache_dir("R", os = "win"), "/Local Settings/Application Data/R/R/Cache" ) }) rappdirs/tests/testthat/test-log.r0000644000176200001440000000077614001366146017034 0ustar liggesuserstest_that("user_cache_dir works as expected", { expect_equal(user_log_dir("R", os = "mac"), "~/Library/Logs/R") withr::local_envvar(XDG_CACHE_HOME = "/cache") expect_equal(user_log_dir("R", os = "unix"), "/cache/R/log") expect_equal(user_log_dir("R", os = "unix", opinion = FALSE), "/cache/R") }) test_that("user_cache_dir works with windows simulation", { skip_on_os("windows") expect_equal( user_log_dir("R", os = "win"), "/Local Settings/Application Data/R/R/Logs" ) }) rappdirs/tests/testthat/_snaps/0000755000176200001440000000000014001377137016366 5ustar liggesusersrappdirs/tests/testthat/_snaps/appdir.md0000644000176200001440000000112614004633050020157 0ustar liggesusers# appdir works as expected Code app <- app_dir("ggplot2", "hadley", os = "mac") Code app$cache() Output [1] "~/Library/Caches/ggplot2" Code app$log() Output [1] "~/Library/Logs/ggplot2" Code app$data() Output [1] "~/Library/Application Support/ggplot2" Code app$config() Output [1] "~/Library/Application Support/ggplot2" Code app$site_data() Output [1] "/Library/Application Support/ggplot2" Code app$site_config() Output [1] "/Library/Application Support/ggplot2" rappdirs/tests/testthat/_snaps/utils.md0000644000176200001440000000034414004633203020041 0ustar liggesusers# check_version works as expected Code expect_equal(check_version("1", NULL), NULL) Warning version is ignored when appname is null Code expect_equal(check_version("1", "R"), "1") rappdirs/tests/testthat/test-appdir.r0000644000176200001440000000034014001353713017511 0ustar liggesuserstest_that("appdir works as expected", { expect_snapshot({ app <- app_dir("ggplot2", "hadley", os = "mac") app$cache() app$log() app$data() app$config() app$site_data() app$site_config() }) }) rappdirs/tests/testthat/test-data.r0000644000176200001440000000635114004114402017144 0ustar liggesuserstest_that("default paths work on mac", { expect_equal(user_data_dir("R", os = "mac"), "~/Library/Application Support/R") expect_equal(user_config_dir("R", os = "mac"), "~/Library/Application Support/R") expect_equal(site_data_dir("R", os = "mac"), "/Library/Application Support/R") expect_equal(site_config_dir("R", os = "mac"), "/Library/Application Support/R") }) test_that("default paths work on linux", { withr::local_envvar( XDG_DATA_HOME = NA, XDG_CONFIG_HOME = NA, XDG_DATA_DIRS = NA, XDG_CONFIG_DIRS = NA, ) expect_equal(user_data_dir("R", os = "unix"), "~/.local/share/R") expect_equal(user_config_dir("R", os = "unix"), "~/.config/R") expect_equal(site_data_dir("R", os = "unix"), "/usr/local/share/R") expect_equal(site_config_dir("R", os = "unix"), "/etc/xdg/R") }) test_that("can override linux paths with envvars", { withr::local_envvar( XDG_DATA_HOME = "A", XDG_CONFIG_HOME = "B", XDG_DATA_DIRS = "C", XDG_CONFIG_DIRS = "D", ) expect_equal(user_data_dir("R", os = "unix"), "A/R") expect_equal(user_config_dir("R", os = "unix"), "B/R") expect_equal(site_data_dir("R", os = "unix"), "C/R") expect_equal(site_config_dir("R", os = "unix"), "D/R") }) test_that("can override with R_USER_DATA_DIR", { withr::local_envvar(R_USER_DATA_DIR = "/test") expect_equal(user_data_dir("R", os = "mac"), "/test/R") withr::local_envvar(R_USER_CONFIG_DIR = "/test") expect_equal(user_config_dir("R", os = "mac"), "/test/R") }) test_that("can optionally use all XDG_DATA_DIRS", { withr::local_envvar(XDG_DATA_DIRS = "/usr/local/share:/usr/share") expect_equal( site_data_dir("R", os = "unix", multipath = TRUE), c("/usr/local/share/R", "/usr/share/R") ) expect_equal( site_data_dir("R", os = "unix", multipath = FALSE), "/usr/local/share/R" ) }) test_that("default paths work in windows simulation", { skip_on_os("windows") expect_equal(user_data_dir("R", os = "win"), "/Local Settings/Application Data/R/R") expect_equal(user_config_dir("R", os = "win"), "/R/R") expect_equal(site_data_dir("R", os = "win"), "/Application Data/R/R") expect_equal(site_config_dir("R", os = "win"), "/Application Data/R/R") }) test_that("can override windows paths with env vars", { skip_on_os("windows") withr::local_envvar(LOCALAPPDATA = NA, PROGRAMDATA = NA) withr::local_envvar(APPDATA = "C:/config") expect_equal( user_config_dir("R", os = "win", roaming = TRUE), "C:/config/R/R" ) withr::local_envvar("USERPROFILE" = "C:/config1") expect_equal( user_config_dir("R", os = "win", roaming = FALSE), "C:/config1/Local Settings/Application Data/R/R" ) withr::local_envvar("LOCALAPPDATA" = "C:/config2") expect_equal( user_config_dir("R", os = "win", roaming = FALSE), "C:/config2/R/R" ) }) test_that("can expand versioned paths", { expect_equal( site_data_dir("R", version = "%V", os = "mac", expand = TRUE), file.path("/Library/Application Support/R", as.character(getRversion())) ) expect_equal( site_data_dir("R", version = "%V", os = "mac", expand = FALSE), "/Library/Application Support/R/%V" ) }) # linux ------------------------------------------------------------------- rappdirs/tests/testthat/test-utils.r0000644000176200001440000000231414004633333017377 0ustar liggesuserstest_that("expand_r_libs_specifiers works as expected", { expect_equal(expand_r_libs_specifiers("%V"), as.character(getRversion())) expect_equal(expand_r_libs_specifiers("%%V"), "%V") expect_equal(expand_r_libs_specifiers(NULL), NULL) }) test_that("file_path drops NULLs", { expect_equal(file_path("a", NULL, "b"), "a/b") }) test_that("file_path is not vectorised", { expect_equal(file_path(c("a", "b"), c("c", "d")), "a/b/c/d") }) test_that("windows fallbacks work", { skip_on_os("windows") withr::local_envvar(LOCALAPPDATA = NA, PROGRAMDATA = NA) expect_equal(win_path_env("roaming"), "") expect_equal(win_path_env("local"), "/Local Settings/Application Data") withr::local_envvar(LOCALAPPDATA = "") expect_equal(win_path_env("local"), "") expect_equal(win_path_env("common"), "/Application Data") withr::local_envvar(PROGRAMDATA = "") expect_equal(win_path_env("common"), "") expect_error(win_path_env("foo"), "invalid") }) test_that("check_version works as expected", { expect_snapshot({ expect_equal(check_version("1", NULL), NULL) expect_equal(check_version("1", "R"), "1") }) }) rappdirs/tests/testthat.R0000644000176200001440000000031214004114402015205 0ustar liggesuserslibrary(testthat) library(rappdirs) # ensure CRAN settings don't affect tests Sys.unsetenv("R_USER_DATA_DIR") Sys.unsetenv("R_USER_CONFIG_DIR") Sys.unsetenv("R_USER_CACHE_DIR") test_check("rappdirs") rappdirs/src/0000755000176200001440000000000014004635344012670 5ustar liggesusersrappdirs/src/init.c0000644000176200001440000000061714001312527013773 0ustar liggesusers#include #include #include // for NULL #include /* .Call calls */ extern SEXP win_path_(SEXP); static const R_CallMethodDef CallEntries[] = { {"win_path_", (DL_FUNC) &win_path_, 1}, {NULL, NULL, 0} }; void R_init_rappdirs(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } rappdirs/src/win-path.c0000644000176200001440000000126414004632436014565 0ustar liggesusers#include #include #ifdef WIN32 #include // SHGetFolderPath documentation: // http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181.aspx SEXP win_path_(SEXP _folder) { int folder = INTEGER(_folder)[0]; TCHAR startupFolder[MAX_PATH]; HRESULT hr = SHGetFolderPath(0, folder, 0, 0, startupFolder); if (SUCCEEDED(hr)) { // Get short path TCHAR shortPath[MAX_PATH]; GetShortPathName(startupFolder, shortPath, MAX_PATH); return mkString(shortPath); } else { // Return NULL if failed return R_NilValue; } } #else SEXP win_path_(SEXP folder) { return R_NilValue; } #endif rappdirs/R/0000755000176200001440000000000014004114402012265 5ustar liggesusersrappdirs/R/cache.r0000644000176200001440000000322614004114402013516 0ustar liggesusers#' Path to user cache directory #' #' @description #' This functions uses `R_USER_CACHE_DIR` if set. Otherwise, they follow #' platform conventions. Typical user cache directories are: #' #' * Mac OS X: `~/Library/Caches/` #' * Linux: `~/.cache/` #' * Win XP: `C:\\Documents and Settings\\\\Local Settings\\Application Data\\\\\\Cache` #' * Vista: `C:\\Users\\\\AppData\\Local\\\\\\Cache` #' #' @section Opinion: #' On Windows the only suggestion in the MSDN docs is that local settings go #' in the `CSIDL_LOCAL_APPDATA` directory. This is identical to the #' non-roaming app data dir (i.e. [user_data_dir()]). But apps typically put #' cache data somewhere *under* this directory so `user_cache_dir()` appends #' `Cache` to the `CSIDL_LOCAL_APPDATA` value, unless `opinion = FALSE`. #' #' @inheritParams user_data_dir #' @param opinion (logical) Use `FALSE` to disable the appending of #' `Cache` on Windows. See discussion below. #' @seealso [tempdir()] for a non-persistent temporary directory. #' @export #' @examples #' user_cache_dir("rappdirs") user_cache_dir <- function(appname = NULL, appauthor = appname, version = NULL, opinion = TRUE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) base <- base_path(os, "CACHE", win = win_path("local"), mac = "~/Library/Caches", unix = Sys.getenv("XDG_CACHE_HOME", "~/.cache") ) switch(check_os(os), win = file_path(base, appauthor, appname, version, if (opinion) "Cache"), mac = file_path(base, appname, version), unix = file_path(base, appname, version) ) } rappdirs/R/log.r0000644000176200001440000000311514001377516013247 0ustar liggesusers#' Path to user log directory #' #' Typical user cache directories are: #' #' \itemize{ #' \item Mac OS X: \file{~/Library/Logs/} #' \item Unix: \file{~/.cache//log}, or under #' \\env{$XDG_CACHE_HOME} if defined #' \item Win XP: \file{C:\\Documents and Settings\\\\Local Settings\\Application Data\\\\\\Logs} #' \item Vista: #' \file{C:\\Users\\\\AppData\\Local\\\\\\Logs} #' } #' #' On Windows the only suggestion in the MSDN docs is that local settings #' go in the `CSIDL_LOCAL_APPDATA` directory. #' #' @section Opinion: #' This function appends \file{Logs} to the `CSIDL_LOCAL_APPDATA` #' value for Windows and appends \file{log} to the user cache dir for Unix. #' This can be disabled with the `opinion = FALSE` option. #' #' @inheritParams user_data_dir #' @param opinion (logical) can be `FALSE` to disable the appending of #' \file{Logs} to the base app data dir for Windows, and \file{log} to the #' base cache dir for Unix. See discussion below. #' @examples #' user_log_dir() #' @export user_log_dir <- function(appname = NULL, appauthor = appname, version = NULL, opinion = TRUE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) switch(check_os(os), win = file_path( win_path("local"), appauthor, appname, version, if (opinion) "Logs" ), mac = file_path("~/Library/Logs", appname, version), unix = file_path( Sys.getenv("XDG_CACHE_HOME", "~/.cache"), appname, version, if (opinion) "log" ) ) } rappdirs/R/utils.r0000644000176200001440000000634714004633062013632 0ustar liggesuserscheck_os <- function(os) { if (is.null(os)) { get_os() } else { if (length(os) != 1 || !is.character(os)) { stop("`os` must be a string", call. = FALSE) } if (!os %in% c("win", "mac", "unix")) { stop("`os` must be one of 'win', 'mac', 'unix'", call. = FALSE) } os } } get_os <- function() { if (.Platform$OS.type == "windows") { "win" } else if (Sys.info()["sysname"] == "Darwin") { "mac" } else { "unix" } } file_path <- function(...) { paste(c(...), collapse = .Platform$file.sep) } "%||%" <- function(a, b) if (is.null(a)) b else a base_path <- function(os, type, win, mac, unix) { name <- paste0("R_USER_", type, "_DIR") val <- Sys.getenv(name) if (!identical(val, "")) { val } else { switch(check_os(os), win = win, mac = mac, unix = unix) } } win_path <- function(type_appdata = "common") { CSIDL_APPDATA <- 26L CSIDL_COMMON_APPDATA <- 35L CSIDL_LOCAL_APPDATA <- 28L switch(type_appdata, roaming = win_path_csidl(CSIDL_APPDATA) %||% win_path_env("roaming"), local = win_path_csidl(CSIDL_LOCAL_APPDATA) %||% win_path_env("local"), common = win_path_csidl(CSIDL_COMMON_APPDATA) %||% win_path_env("common") ) } #' @useDynLib rappdirs, .registration=TRUE win_path_csidl <- function(csidl) { stopifnot(is.integer(csidl), length(csidl) == 1) path <- .Call(win_path_, csidl, PACKAGE = "rappdirs") path } # How to get reasonable window paths via environmental variables win_path_env <- function(type) { if (type == "roaming") { env_fallback("APPDATA") } else if (type == "local") { path <- Sys.getenv("LOCALAPPDATA", unset = NA) if (is.na(path)) { # environmental variable not defined in XP path <- file.path( env_fallback("USERPROFILE"), "Local Settings", "Application Data" ) } path } else if (type == "common") { path <- Sys.getenv("PROGRAMDATA", unset = NA) if (is.na(path)) { path <- file.path(env_fallback("ALLUSERPROFILE"), "Application Data") } path } else { stop("invalid `type` argument") } } env_fallback <- function(env) { val <- Sys.getenv(env) if (identical(val, "")) { if (get_os() == "win") { stop("Can't find envvar '", env, "'", call. = FALSE) } else { # Fall back so examples still work when not on windows paste0("<", env, ">") } } else { val } } # version ----------------------------------------------------------------- check_version <- function(version, appname, expand = FALSE) { if (is.null(appname) && !is.null(version)) { warning("version is ignored when appname is null", call. = FALSE) NULL } else { if (expand) { version <- expand_r_libs_specifiers(version) } version } } expand_r_libs_specifiers <- function(x) { if (is.null(x)) { return(NULL) } rversion <- getRversion() x <- gsub_special("%V", rversion, x) x <- gsub_special("%v", paste(rversion$major, rversion$minor, sep = "."), x) x <- gsub_special("%p", R.version$platform, x) x <- gsub_special("%o", R.version$os, x) x <- gsub_special("%a", R.version$arch, x) x <- gsub("%%", "%", x) x } gsub_special <- function(pattern, replacement, x) { gsub(paste0("([^%]|^)", pattern), paste0("\\1", replacement), x) } rappdirs/R/data.r0000644000176200001440000001531114004633044013372 0ustar liggesusers#' Path to user config/data directories #' #' @description #' `user_data_dir()` returns path to the user-specific data directory and #' `user_config_dir()` returns full path to the user-specific configuration #' directory. These are the same on Windows and Mac but different on Linux. #' #' These functions first use `R_USER_DATA_DIR` and `R_USER_CONFIG_DIR` if set. #' Otherwise, they follow platform conventions. Typical user config and data #' directories are: #' #' * Mac OS X: `~/Library/Application Support/` #' * Win XP (not roaming): `C:\\Documents and Settings\\\\Data\\\\` #' * Win XP (roaming): `C:\\Documents and Settings\\\\Local Settings\\Data\\\\` #' * Win 7 (not roaming): `C:\\Users\\\\AppData\\Local\\\\` #' * Win 7 (roaming): `C:\\Users\\\\AppData\\Roaming\\\\` #' #' Only Linux makes the distinction between config and data: #' #' * Data: `~/.local/share/` #' * Config: `~/.config/` #' #' @param appname is the name of application. If NULL, just the system #' directory is returned. #' @param appauthor (only required and used on Windows) is the name of the #' appauthor or distributing body for this application. Typically #' it is the owning company name. This falls back to appname. #' @param version is an optional version path element to append to the #' path. You might want to use this if you want multiple versions #' of your app to be able to run independently. If used, this #' would typically be `"."`. Only applied when appname #' is not NULL. #' @param roaming (logical, default `FALSE`) can be set `TRUE` to #' use the Windows roaming appdata directory. That means that for users on #' a Windows network setup for roaming profiles, this user data will be #' sync'd on login. See #' #' for a discussion of issues. #' @param os Operating system whose conventions are used to construct the #' requested directory. Possible values are "win", "mac", "unix". If `NULL` #' (the default) then the current OS will be used. #' @param expand If TRUE (the default) will expand the `R_LIBS` specifiers with their equivalents. #' See [R_LIBS()] for list of all possibly specifiers. #' @export #' @examples #' user_data_dir("rappdirs") #' #' user_config_dir("rappdirs", roaming = TRUE, os = "win") #' user_config_dir("rappdirs", roaming = FALSE, os = "win") #' user_config_dir("rappdirs", os = "unix") #' user_config_dir("rappdirs", os = "mac") #' user_config_dir("rappdirs", version = "%p-platform/%v") user_data_dir <- function(appname = NULL, appauthor = appname, version = NULL, roaming = FALSE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) base <- base_path(os, "DATA", win = win_path(ifelse(roaming, "roaming", "local")), mac = "~/Library/Application Support", unix = Sys.getenv("XDG_DATA_HOME", "~/.local/share") ) switch(check_os(os), win = file_path(base, appauthor, appname, version), mac = file_path(base, appname, version), unix = file_path(base, appname, version) ) } #' @rdname user_data_dir #' @export user_config_dir <- function(appname = NULL, appauthor = appname, version = NULL, roaming = TRUE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) base <- base_path(os, "CONFIG", win = win_path(ifelse(roaming, "roaming", "local")), mac = "~/Library/Application Support", unix = Sys.getenv("XDG_CONFIG_HOME", "~/.config") ) switch(check_os(os), win = file_path(base, appauthor, appname, version), mac = file_path(base, appname, version), unix = file_path(base, appname, version) ) } #' Path to shared data/config directories #' #' `site_data_dir` returns full path to the user-shared data dir for this application. #' `site_config_dir` returns full path to the user-specific configuration directory for this application #' which returns the same path as site data directory in Windows and Mac but a different one for Unix. #' Typical user-shared data directories are: #' #' * Mac OS X: `/Library/Application Support/` #' * Unix: `/usr/local/share:/usr/share/` #' * Win XP: `C:\\Documents and Settings\\All Users\\Application Data\\\\` #' * Vista: (Fail! `C:\\ProgramData` is a hidden *system* directory on Vista.) #' * Win 7: `C:\\ProgramData\\\\`. Hidden, but writeable on Win 7. #' #' Unix also specifies a separate location for user-shared configuration data in \env{$XDG_CONFIG_DIRS}. #' #' * Unix: `/etc/xdg/`, in \env{$XDG_CONFIG_HOME} if defined #' #' For Unix, this returns the first default. Set the `multipath=TRUE` to guarantee returning all directories. #' #' @inheritParams user_data_dir #' @param multipath is an optional parameter only applicable to *nix #' which indicates that the entire list of data dirs should be returned #' By default, the first directory is returned #' @section Warning: #' Do not use this on Windows. See the note above for why. #' @export site_data_dir <- function(appname = NULL, appauthor = appname, version = NULL, multipath = FALSE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) switch(check_os(os), win = file_path(win_path("common"), appauthor, appname, version), mac = file_path("/Library/Application Support", appname, version), unix = file_path_site_unix( Sys.getenv("XDG_DATA_DIRS", "/usr/local/share:/usr/share"), appname, version, multipath ) ) } #' @rdname site_data_dir #' @export site_config_dir <- function(appname = NULL, appauthor = appname, version = NULL, multipath = FALSE, expand = TRUE, os = NULL) { version <- check_version(version, appname, expand) switch(check_os(os), win = file_path(win_path("common"), appauthor, appname, version), mac = file_path("/Library/Application Support", appname, version), unix = file_path_site_unix( Sys.getenv("XDG_CONFIG_DIRS", "/etc/xdg"), appname, version, multipath ) ) } # wrapper with `multipath` and use `parse_path_string` for cleaner switch statement file_path_site_unix <- function(sys_getenv, appname, version, multipath = FALSE) { paths <- parse_path_string(sys_getenv) if (multipath) { vapply(paths, file_path, appname, version, FUN.VALUE = character(1), USE.NAMES = FALSE ) } else { file_path(paths[[1]], appname, version) } } parse_path_string <- function(path, sep = ":") { unique(strsplit(path, sep)[[1]]) } rappdirs/R/rappdirs-package.r0000644000176200001440000000026714001364522015701 0ustar liggesusers#' @section Main functions: #' * [user_data_dir()] #' * [user_config_dir()] #' * [user_cache_dir()] #' * [site_data_dir()] #' * [user_log_dir()] #' @keywords internal "_PACKAGE" rappdirs/R/appdir.r0000644000176200001440000000233614004126146013743 0ustar liggesusers#' Record app information in a convenient object #' #' @description #' Has methods: #' * `$cache()` #' * `$log()` #' * `$data()` #' * `$config()` #' * `$site_data()` #' * `$site_config()` #' #' @inheritParams user_data_dir #' @keywords internal #' @export #' @examples #' ggplot2_app <- app_dir("ggplot2", "hadley") #' ggplot2_app$cache() #' ggplot2_app$log() #' ggplot2_app$data() #' ggplot2_app$config() #' ggplot2_app$site_config() #' ggplot2_app$site_data() app_dir <- function(appname = NULL, appauthor = appname, version = NULL, expand = TRUE, os = NULL) { os <- check_os(os) list( cache = function(opinion = TRUE) user_cache_dir(appname, appauthor, version, opinion, expand, os), log = function(opinion = TRUE) user_log_dir(appname, appauthor, version, opinion, expand, os), data = function(roaming = FALSE) user_data_dir(appname, appauthor, version, roaming, expand, os), config = function(roaming = FALSE) user_config_dir(appname, appauthor, version, roaming, expand, os), site_data = function(multipath = FALSE) site_data_dir(appname, appauthor, version, multipath, expand, os), site_config = function(multipath = FALSE) site_config_dir(appname, appauthor, version, multipath, expand, os), os = os ) } rappdirs/NEWS.md0000644000176200001440000000137014004635326013200 0ustar liggesusers# rappdirs 0.3.3 * rappdirs functions are no longer vectorised; this was an accidental change in 0.3.2 (#32). # rappdirs 0.3.2 * `user_data_dir()`, `use_cache_dir()` and `use_config_dir()` now respect `R_USER_DATA_DIR`, `R_USER_CACHE_DIR` and `R_USER_CONFIG_DIR` env vars (#27). * No longer uses methods package. # rappdirs 0.3.1 Minor R CMD check and test fixes. # rappdirs 0.3.0 * first CRAN release * `xxx_dir()` functions only use version when appname is not null * docs: basic package docs (?rappdirs) * docs: clarify primary purpose of os argument in `xxx_dir()` i.e. testing * fix typo in function name in README.md (app_dirs -> app_dir) * dev: add travis continuous integration * dev: add rstudio project * dev: update to roxygen2 v4.0.1 rappdirs/MD50000644000176200001440000000257214005441262012412 0ustar liggesusersdf3623238b0c76307ddcb2619311102f *DESCRIPTION d913e1265e23e90746f1d93e3a5e8d42 *LICENSE 26aa9fe918c0839a3102c6999fb17556 *NAMESPACE 5a9aa06f5a5b913cb3249476c5cc2d76 *NEWS.md 9c4414e52b43e2591684452ec18f6d30 *R/appdir.r 53a7355c40fcdd2e54a55f23a5f04c3e *R/cache.r ab9d428106e796bbc2952620f1165433 *R/data.r c4098515baa077ba82984264bce17602 *R/log.r 58c4e393ecc69a1caa219e581eb027f5 *R/rappdirs-package.r 2bd7a166b759ecec68b864d761a1245e *R/utils.r 503074ef6b8c06698662394896da60e9 *README.md 2e3c2d0275445a7c080587419b776fc5 *man/app_dir.Rd 43243833280629472766b6c3b1b6533b *man/rappdirs-package.Rd a111a715ecb11b3c5b03845e2eb04f1a *man/site_data_dir.Rd 208a6540b197d9a2c6c64d24dd83b10b *man/user_cache_dir.Rd 378802ff64d6d7b519e9b32f9cd9067d *man/user_data_dir.Rd d8a90ff3fafe3e5ae35d8ec24343b6fa *man/user_log_dir.Rd 58392a1a4462ea49bbae905a5064f070 *src/init.c 71edc67598de2e2996957c011c4b5d8c *src/win-path.c ced484c4dfa214b2b7f3b62450588c19 *tests/testthat.R 7e44d9dcebf3cead31734632ec2a113a *tests/testthat/_snaps/appdir.md c6e7bd8276e4493656d22576fe34b95a *tests/testthat/_snaps/utils.md e5eb0c0adce1830f91c07e240fb4755e *tests/testthat/test-appdir.r 2c6a3a0d4428b5ce807ca2e4b373d64d *tests/testthat/test-cache.r 3151b03a5137c3576f154879fbe5c307 *tests/testthat/test-data.r fc142b51591fea8af4a441f810fd5e66 *tests/testthat/test-log.r 87e3003c8eb3dceafbde06434445c3e9 *tests/testthat/test-utils.r