https://github.com/briandconnelly/xdgbasedir
R implementation of X Desktop Group Base Directory Specification
https://github.com/briandconnelly/xdgbasedir
r rstats xdg xdg-basedir xdg-compliance
Last synced: 5 months ago
JSON representation
R implementation of X Desktop Group Base Directory Specification
- Host: GitHub
- URL: https://github.com/briandconnelly/xdgbasedir
- Owner: briandconnelly
- License: other
- Created: 2023-10-21T23:04:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-22T01:16:52.000Z (over 1 year ago)
- Last Synced: 2023-10-23T00:25:08.646Z (over 1 year ago)
- Topics: r, rstats, xdg, xdg-basedir, xdg-compliance
- Language: R
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - briandconnelly/xdgbasedir - R implementation of X Desktop Group Base Directory Specification (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# xdgbasedir
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://CRAN.R-project.org/package=xdgbasedir)
[](https://github.com/briandconnelly/xdgbasedir/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/briandconnelly/xdgbasedir?branch=main)xdgbasedir is R package that allows you to work with paths that comply with the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
These functions allow you to get the value associated with the relevant environment variable and to build paths from them:
| XDG Variable | xdgbasedir function |
|--------------------|--------------------------|
| `$XDG_CACHE_HOME` | `path_xdg_cache_home()` |
| `$XDG_CONFIG_HOME` | `path_xdg_config_home()` |
| `$XDG_DATA_HOME` | `path_xdg_data_home()` |
| `$XDG_RUNTIME_DIR` | `path_xdg_runtime_dir()` |
| `$XDG_STATE_HOME` | `path_xdg_state_home()` |For example, we get the path for storing our configuration file, `myconfig.json` (on MacOS):
```{r include=FALSE}
Sys.unsetenv("XDG_CONFIG_HOME")
``````{r add config file}
library(xdgbasedir)path_xdg_config_home("myconfig.json")
```These functions allow you to get an ordered list of directories:
| XDG Variable. | xdgbasedir function |
|--------------------|--------------------------|
| `$XDG_CONFIG_DIRS` | `path_xdg_config_dirs()` |
| `$XDG_DATA_DIRS` | `path_xdg_data_dirs()` |```{r datadirs example}
path_xdg_data_dirs()
```## Installation
You can install the development version of xdgbasedir like so:
``` r
# install.packages("remotes")
remotes::install_github("briandconnelly/xdgbasedir")
```## Example
Let's say we wanted to read our RStudio Desktop preferences file, `rstudio-prefs.json`.
Since RStudio [complies](https://docs.posit.co/ide/desktop-pro/settings/settings.html) with the XDG Base Directory Specification, we can easily find that file no matter how the user has configured their environment.```{r load rstudio-prefs.json}
library(xdgbasedir)prefs_file <- path_xdg_config_home("rstudio-prefs.json")
prefs_file
```