Pins the given resource locally or to the given board.

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.

pin() will stores data frames in two files, an R native file and a 'CSV' file. To force saving a pin only using R's native (RDS) format, you can use pin(I(data)). This can improve performance and size at the cost of making the pin unreadable from other tools and programming languages.

Examples

# define temporary local board board <- board_temp() # cache the mtcars dataset pin(mtcars, board = board) # cache computation over mtcars pin(mtcars[mtcars$mpg > 30, ], name = "mtefficient", board = board) # retrieve cached pin pin_get("mtefficient", board = board)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
# 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", board = board) # cache and read csv path <- pin(resource, board = board) path
#> [1] "/tmp/RtmpEIp4cf/pins-384d58161aa/example-retail-sales/example_retail_sales.csv"
head(read.csv(path))
#> ds y #> 1 1992-01-01 146376 #> 2 1992-02-01 147079 #> 3 1992-03-01 159336 #> 4 1992-04-01 163669 #> 5 1992-05-01 170068 #> 6 1992-06-01 168663