Learn R Programming

pins (version 0.1.1)

pin: Pin Resource

Description

Pins the given resource locally or to the given board.

Usage

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

Run this code
# NOT RUN {
library(pins)

# cache the mtcars dataset
pin(mtcars)

# cache computation oveer 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))

# }

Run the code above in your browser using DataLab