Skip to contents

Reuse R objects

Usage

reuse(
  x,
  name,
  board = reuse::board(),
  type = "qs",
  update = getOption("reuse.update", default = FALSE)
)

board()

Arguments

x

An object (typically a data frame) to pin.

name

Pin name.

board

A pin board, created by board_folder(), board_rsconnect(), board_url() or another board_ function.

type

File type used to save x to disk. Must be one of "csv", "rds", "json", "arrow", or "qs". If not supplied will use json for bare lists and rds for everything else.

update

Logical. update the cache?

Value

The R object written to or read from the cache.

Examples

one <- 1 %>% reuse("one")
#> Creating new version '20220427T134428Z-4ebb2'
#> Writing to pin 'one'
two <- 2 %>% reuse("one")
two
#> [1] 1

two <- 2 %>% reuse("one", update = TRUE)
#> Replacing version '20220427T134428Z-4ebb2' with '20220427T134428Z-63a73'
#> Writing to pin 'one'
two
#> [1] 2
withr::local_options(list(reuse.board = pins::board_temp()))
board()
#> Pin board <pins_board_folder>
#> Path: '~/.cache/reuse'
#> Cache size: 0
#> Pins [1]: 'one'

pins::pin_exists(board(), name = "one")
#> [1] TRUE
1 %>% reuse("one")
#> [1] 2
pins::pin_exists(board(), name = "one")
#> [1] TRUE