pin: Pin Resource

Description Usage Arguments Details Examples

View source: R/pin.R

Description

Pins the given resource locally or to the given board.

Usage

1
pin(x, name = NULL, description = NULL, board = NULL, ...)

Arguments

x

An object, local file or remote URL to pin.

name

The name for the dataset or object.

description

Optional description for this pin.

board

The board where this pin will be placed.

...

Additional parameters.

Details

pin() allows you to cache remote resources and intermediate results with ease. When caching remote resources, usually URLs, it will check for HTTP caching headers to avoid re-downloading when the remote result has not changed.

This makes it ideal to support reproducible research by requiring manual instruction to download resources before running your R script.

In addition, pin() still works when working offline or when the remote resource becomes unavailable; when this happens, a warning will be triggered but your code will continue to work.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(pins)

# define local board
board_register_local(cache = tempfile())

# cache the mtcars dataset
pin(mtcars)

# cache computation over mtcars
mtcars[mtcars$mpg > 30,] %>%
  pin(name = "mtefficient")

# retrieve cached pin
pin_get("mtefficient")

# url to remote resource
resource <- file.path("https://raw.githubusercontent.com/facebook/prophet",
                      "master/examples/example_retail_sales.csv")

# cache remote resource
pin(resource, name = "example_retail_sales")

# load cached csv
pin_get("example_retail_sales") %>% read.csv()

# cache and read csv
read.csv(pin(resource))

pins documentation built on April 14, 2020, 6:44 p.m.