# Select and Manage the Private R Cache

Datamonger for R · 0.2.0

[Source](<https://github.com/jolars/datamonger/blob/fbf4417f4d75b63acbb7eb39975add7aedbff2f6/packages/r/R/cache-management.R>)

```r
cache_clean(dataset = NULL, older_than = NULL, cache_dir = NULL)
```

<a id="select-and-manage-the-private-r-cache"></a>

## Select and Manage the Private R Cache

Datamonger uses the cache returned by `tools::R_user_dir()` by default. An
explicit path can select another persistent or temporary location. Eviction
is manual, and active objects are skipped.


<a id="usage"></a>

## Usage

```r
datamonger_cache_dir(cache_dir = NULL)
```

```r
cache_info(cache_dir = NULL)
```

```r
cache_clean(dataset = NULL, older_than = NULL, cache_dir = NULL)
```

<a id="arguments"></a>

## Arguments

`cache_dir`

An explicit cache path, or `NULL` for the platform default.

`dataset`

A canonical `source:name@version` filter.

`older_than`

A nonnegative `difftime` or number of seconds.

<a id="value"></a>

## Value

`datamonger_cache_dir()` returns a path without creating it. `cache_info()`
returns a cache inventory. `cache_clean()` reports removed and skipped
objects and the number of bytes removed.


<a id="examples"></a>

## Examples

```r
cache <- datamonger_cache_dir(tempfile("datamonger-cache-"))
dir.create(cache)
cache_info(cache_dir = cache)
cache_clean(cache_dir = cache)
unlink(cache, recursive = TRUE)
```

```text
<datamonger_cache_info>
  location: /tmp/RtmpxwLIck/datamonger-cache-242e33051be8
  entries: 0
  total_size: 0 bytes
```

```text
$location
[1] "/tmp/RtmpxwLIck/datamonger-cache-242e33051be8"

$removed
list()

$skipped
list()

$bytes_removed
[1] 0

attr(,"class")
[1] "datamonger_cache_clean_result"
```

## Same API in

- [Datamonger for Julia: `Datamonger.cache_clean`](<../../julia/reference/cef249eb6b1ceb1d16bbdc2e07787d287dc0b4b4481f33e04571cb81ddcf1444>)
- [Datamonger for Python: `datamonger.cache_clean`](<../../python/reference/859b08991e23f39162ef79c93dfaa0b0169dd6a69c294eb890c38cd8380c0a13>)
