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.

Examples

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")
#> # A tibble: 4 x 11 #> mpg cyl disp hp drat wt qsec vs am gear carb #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 32.4 4 78.7 66 4.08 2.2 19.5 1 1 4 1 #> 2 30.4 4 75.7 52 4.93 1.62 18.5 1 1 4 2 #> 3 33.9 4 71.1 65 4.22 1.84 19.9 1 1 4 1 #> 4 30.4 4 95.1 113 3.77 1.51 16.9 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") # load cached csv pin_get("example_retail_sales") %>% read.csv()
#> 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 #> 7 1992-07-01 169890 #> 8 1992-08-01 170364 #> 9 1992-09-01 164617 #> 10 1992-10-01 173655 #> 11 1992-11-01 171547 #> 12 1992-12-01 208838 #> 13 1993-01-01 153221 #> 14 1993-02-01 150087 #> 15 1993-03-01 170439 #> 16 1993-04-01 176456 #> 17 1993-05-01 182231 #> 18 1993-06-01 181535 #> 19 1993-07-01 183682 #> 20 1993-08-01 183318 #> 21 1993-09-01 177406 #> 22 1993-10-01 182737 #> 23 1993-11-01 187443 #> 24 1993-12-01 224540 #> 25 1994-01-01 161349 #> 26 1994-02-01 162841 #> 27 1994-03-01 192319 #> 28 1994-04-01 189569 #> 29 1994-05-01 194927 #> 30 1994-06-01 197946 #> 31 1994-07-01 193355 #> 32 1994-08-01 202388 #> 33 1994-09-01 193954 #> 34 1994-10-01 197956 #> 35 1994-11-01 202520 #> 36 1994-12-01 241111 #> 37 1995-01-01 175344 #> 38 1995-02-01 172138 #> 39 1995-03-01 201279 #> 40 1995-04-01 196039 #> 41 1995-05-01 210478 #> 42 1995-06-01 211844 #> 43 1995-07-01 203411 #> 44 1995-08-01 214248 #> 45 1995-09-01 202122 #> 46 1995-10-01 204044 #> 47 1995-11-01 212190 #> 48 1995-12-01 247491 #> 49 1996-01-01 185019 #> 50 1996-02-01 192380 #> 51 1996-03-01 212110 #> 52 1996-04-01 211718 #> 53 1996-05-01 226936 #> 54 1996-06-01 217511 #> 55 1996-07-01 218111 #> 56 1996-08-01 226062 #> 57 1996-09-01 209250 #> 58 1996-10-01 222663 #> 59 1996-11-01 223953 #> 60 1996-12-01 258081 #> 61 1997-01-01 200389 #> 62 1997-02-01 197556 #> 63 1997-03-01 225133 #> 64 1997-04-01 220329 #> 65 1997-05-01 234190 #> 66 1997-06-01 227365 #> 67 1997-07-01 231521 #> 68 1997-08-01 235252 #> 69 1997-09-01 222807 #> 70 1997-10-01 232251 #> 71 1997-11-01 228284 #> 72 1997-12-01 271054 #> 73 1998-01-01 207853 #> 74 1998-02-01 203863 #> 75 1998-03-01 230313 #> 76 1998-04-01 234503 #> 77 1998-05-01 245027 #> 78 1998-06-01 244067 #> 79 1998-07-01 241431 #> 80 1998-08-01 240462 #> 81 1998-09-01 231243 #> 82 1998-10-01 244234 #> 83 1998-11-01 240991 #> 84 1998-12-01 288969 #> 85 1999-01-01 218126 #> 86 1999-02-01 220650 #> 87 1999-03-01 253550 #> 88 1999-04-01 250783 #> 89 1999-05-01 262113 #> 90 1999-06-01 260918 #> 91 1999-07-01 262051 #> 92 1999-08-01 265089 #> 93 1999-09-01 253905 #> 94 1999-10-01 258040 #> 95 1999-11-01 264106 #> 96 1999-12-01 317659 #> 97 2000-01-01 236422 #> 98 2000-02-01 250580 #> 99 2000-03-01 279515 #> 100 2000-04-01 264417 #> 101 2000-05-01 283706 #> 102 2000-06-01 281288 #> 103 2000-07-01 271146 #> 104 2000-08-01 283944 #> 105 2000-09-01 269155 #> 106 2000-10-01 270899 #> 107 2000-11-01 276507 #> 108 2000-12-01 319958 #> 109 2001-01-01 250746 #> 110 2001-02-01 247772 #> 111 2001-03-01 280449 #> 112 2001-04-01 274925 #> 113 2001-05-01 296013 #> 114 2001-06-01 287881 #> 115 2001-07-01 279098 #> 116 2001-08-01 294763 #> 117 2001-09-01 261924 #> 118 2001-10-01 291596 #> 119 2001-11-01 287537 #> 120 2001-12-01 326202 #> 121 2002-01-01 255598 #> 122 2002-02-01 253086 #> 123 2002-03-01 285261 #> 124 2002-04-01 284747 #> 125 2002-05-01 300402 #> 126 2002-06-01 288854 #> 127 2002-07-01 295433 #> 128 2002-08-01 307256 #> 129 2002-09-01 273189 #> 130 2002-10-01 287540 #> 131 2002-11-01 290705 #> 132 2002-12-01 337006 #> 133 2003-01-01 268328 #> 134 2003-02-01 259051 #> 135 2003-03-01 293693 #> 136 2003-04-01 294251 #> 137 2003-05-01 312389 #> 138 2003-06-01 300998 #> 139 2003-07-01 309923 #> 140 2003-08-01 317056 #> 141 2003-09-01 293890 #> 142 2003-10-01 304036 #> 143 2003-11-01 301265 #> 144 2003-12-01 357577 #> 145 2004-01-01 281460 #> 146 2004-02-01 282444 #> 147 2004-03-01 319077 #> 148 2004-04-01 315191 #> 149 2004-05-01 328408 #> 150 2004-06-01 321044 #> 151 2004-07-01 328000 #> 152 2004-08-01 326317 #> 153 2004-09-01 313524 #> 154 2004-10-01 319726 #> 155 2004-11-01 324259 #> 156 2004-12-01 387155 #> 157 2005-01-01 293261 #> 158 2005-02-01 295062 #> 159 2005-03-01 339141 #> 160 2005-04-01 335632 #> 161 2005-05-01 345348 #> 162 2005-06-01 350945 #> 163 2005-07-01 351827 #> 164 2005-08-01 355701 #> 165 2005-09-01 333289 #> 166 2005-10-01 336134 #> 167 2005-11-01 343798 #> 168 2005-12-01 405608 #> 169 2006-01-01 318546 #> 170 2006-02-01 314051 #> 171 2006-03-01 361993 #> 172 2006-04-01 351667 #> 173 2006-05-01 373560 #> 174 2006-06-01 366615 #> 175 2006-07-01 362203 #> 176 2006-08-01 375795 #> 177 2006-09-01 346214 #> 178 2006-10-01 348796 #> 179 2006-11-01 356928 #> 180 2006-12-01 417991 #> 181 2007-01-01 328877 #> 182 2007-02-01 323162 #> 183 2007-03-01 374142 #> 184 2007-04-01 358535 #> 185 2007-05-01 391512 #> 186 2007-06-01 376639 #> 187 2007-07-01 372354 #> 188 2007-08-01 388016 #> 189 2007-09-01 353936 #> 190 2007-10-01 368681 #> 191 2007-11-01 377802 #> 192 2007-12-01 426077 #> 193 2008-01-01 342697 #> 194 2008-02-01 343937 #> 195 2008-03-01 372923 #> 196 2008-04-01 368923 #> 197 2008-05-01 397969 #> 198 2008-06-01 378490 #> 199 2008-07-01 383686 #> 200 2008-08-01 382852 #> 201 2008-09-01 350560 #> 202 2008-10-01 349884 #> 203 2008-11-01 335571 #> 204 2008-12-01 384286 #> 205 2009-01-01 310269 #> 206 2009-02-01 299488 #> 207 2009-03-01 328568 #> 208 2009-04-01 329866 #> 209 2009-05-01 347768 #> 210 2009-06-01 344439 #> 211 2009-07-01 348106 #> 212 2009-08-01 353473 #> 213 2009-09-01 324708 #> 214 2009-10-01 338630 #> 215 2009-11-01 339386 #> 216 2009-12-01 400264 #> 217 2010-01-01 314640 #> 218 2010-02-01 311022 #> 219 2010-03-01 360819 #> 220 2010-04-01 356460 #> 221 2010-05-01 365713 #> 222 2010-06-01 358675 #> 223 2010-07-01 362027 #> 224 2010-08-01 362682 #> 225 2010-09-01 346069 #> 226 2010-10-01 355212 #> 227 2010-11-01 365809 #> 228 2010-12-01 426654 #> 229 2011-01-01 335608 #> 230 2011-02-01 337352 #> 231 2011-03-01 387092 #> 232 2011-04-01 380754 #> 233 2011-05-01 391970 #> 234 2011-06-01 388636 #> 235 2011-07-01 384600 #> 236 2011-08-01 394548 #> 237 2011-09-01 374895 #> 238 2011-10-01 379364 #> 239 2011-11-01 391081 #> 240 2011-12-01 451669 #> 241 2012-01-01 355058 #> 242 2012-02-01 372523 #> 243 2012-03-01 414275 #> 244 2012-04-01 393035 #> 245 2012-05-01 418648 #> 246 2012-06-01 400996 #> 247 2012-07-01 396020 #> 248 2012-08-01 417911 #> 249 2012-09-01 385597 #> 250 2012-10-01 399341 #> 251 2012-11-01 410992 #> 252 2012-12-01 461994 #> 253 2013-01-01 375537 #> 254 2013-02-01 373938 #> 255 2013-03-01 421638 #> 256 2013-04-01 408381 #> 257 2013-05-01 436985 #> 258 2013-06-01 414701 #> 259 2013-07-01 422357 #> 260 2013-08-01 434950 #> 261 2013-09-01 396199 #> 262 2013-10-01 415740 #> 263 2013-11-01 423611 #> 264 2013-12-01 477205 #> 265 2014-01-01 383399 #> 266 2014-02-01 380315 #> 267 2014-03-01 432806 #> 268 2014-04-01 431415 #> 269 2014-05-01 458822 #> 270 2014-06-01 433152 #> 271 2014-07-01 443005 #> 272 2014-08-01 450913 #> 273 2014-09-01 420871 #> 274 2014-10-01 437702 #> 275 2014-11-01 437910 #> 276 2014-12-01 501232 #> 277 2015-01-01 397252 #> 278 2015-02-01 386935 #> 279 2015-03-01 444110 #> 280 2015-04-01 438217 #> 281 2015-05-01 462615 #> 282 2015-06-01 448229 #> 283 2015-07-01 457710 #> 284 2015-08-01 456340 #> 285 2015-09-01 430917 #> 286 2015-10-01 444959 #> 287 2015-11-01 444507 #> 288 2015-12-01 518253 #> 289 2016-01-01 400928 #> 290 2016-02-01 413554 #> 291 2016-03-01 460093 #> 292 2016-04-01 450935 #> 293 2016-05-01 471421
# cache and read csv read.csv(pin(resource))
#> 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 #> 7 1992-07-01 169890 #> 8 1992-08-01 170364 #> 9 1992-09-01 164617 #> 10 1992-10-01 173655 #> 11 1992-11-01 171547 #> 12 1992-12-01 208838 #> 13 1993-01-01 153221 #> 14 1993-02-01 150087 #> 15 1993-03-01 170439 #> 16 1993-04-01 176456 #> 17 1993-05-01 182231 #> 18 1993-06-01 181535 #> 19 1993-07-01 183682 #> 20 1993-08-01 183318 #> 21 1993-09-01 177406 #> 22 1993-10-01 182737 #> 23 1993-11-01 187443 #> 24 1993-12-01 224540 #> 25 1994-01-01 161349 #> 26 1994-02-01 162841 #> 27 1994-03-01 192319 #> 28 1994-04-01 189569 #> 29 1994-05-01 194927 #> 30 1994-06-01 197946 #> 31 1994-07-01 193355 #> 32 1994-08-01 202388 #> 33 1994-09-01 193954 #> 34 1994-10-01 197956 #> 35 1994-11-01 202520 #> 36 1994-12-01 241111 #> 37 1995-01-01 175344 #> 38 1995-02-01 172138 #> 39 1995-03-01 201279 #> 40 1995-04-01 196039 #> 41 1995-05-01 210478 #> 42 1995-06-01 211844 #> 43 1995-07-01 203411 #> 44 1995-08-01 214248 #> 45 1995-09-01 202122 #> 46 1995-10-01 204044 #> 47 1995-11-01 212190 #> 48 1995-12-01 247491 #> 49 1996-01-01 185019 #> 50 1996-02-01 192380 #> 51 1996-03-01 212110 #> 52 1996-04-01 211718 #> 53 1996-05-01 226936 #> 54 1996-06-01 217511 #> 55 1996-07-01 218111 #> 56 1996-08-01 226062 #> 57 1996-09-01 209250 #> 58 1996-10-01 222663 #> 59 1996-11-01 223953 #> 60 1996-12-01 258081 #> 61 1997-01-01 200389 #> 62 1997-02-01 197556 #> 63 1997-03-01 225133 #> 64 1997-04-01 220329 #> 65 1997-05-01 234190 #> 66 1997-06-01 227365 #> 67 1997-07-01 231521 #> 68 1997-08-01 235252 #> 69 1997-09-01 222807 #> 70 1997-10-01 232251 #> 71 1997-11-01 228284 #> 72 1997-12-01 271054 #> 73 1998-01-01 207853 #> 74 1998-02-01 203863 #> 75 1998-03-01 230313 #> 76 1998-04-01 234503 #> 77 1998-05-01 245027 #> 78 1998-06-01 244067 #> 79 1998-07-01 241431 #> 80 1998-08-01 240462 #> 81 1998-09-01 231243 #> 82 1998-10-01 244234 #> 83 1998-11-01 240991 #> 84 1998-12-01 288969 #> 85 1999-01-01 218126 #> 86 1999-02-01 220650 #> 87 1999-03-01 253550 #> 88 1999-04-01 250783 #> 89 1999-05-01 262113 #> 90 1999-06-01 260918 #> 91 1999-07-01 262051 #> 92 1999-08-01 265089 #> 93 1999-09-01 253905 #> 94 1999-10-01 258040 #> 95 1999-11-01 264106 #> 96 1999-12-01 317659 #> 97 2000-01-01 236422 #> 98 2000-02-01 250580 #> 99 2000-03-01 279515 #> 100 2000-04-01 264417 #> 101 2000-05-01 283706 #> 102 2000-06-01 281288 #> 103 2000-07-01 271146 #> 104 2000-08-01 283944 #> 105 2000-09-01 269155 #> 106 2000-10-01 270899 #> 107 2000-11-01 276507 #> 108 2000-12-01 319958 #> 109 2001-01-01 250746 #> 110 2001-02-01 247772 #> 111 2001-03-01 280449 #> 112 2001-04-01 274925 #> 113 2001-05-01 296013 #> 114 2001-06-01 287881 #> 115 2001-07-01 279098 #> 116 2001-08-01 294763 #> 117 2001-09-01 261924 #> 118 2001-10-01 291596 #> 119 2001-11-01 287537 #> 120 2001-12-01 326202 #> 121 2002-01-01 255598 #> 122 2002-02-01 253086 #> 123 2002-03-01 285261 #> 124 2002-04-01 284747 #> 125 2002-05-01 300402 #> 126 2002-06-01 288854 #> 127 2002-07-01 295433 #> 128 2002-08-01 307256 #> 129 2002-09-01 273189 #> 130 2002-10-01 287540 #> 131 2002-11-01 290705 #> 132 2002-12-01 337006 #> 133 2003-01-01 268328 #> 134 2003-02-01 259051 #> 135 2003-03-01 293693 #> 136 2003-04-01 294251 #> 137 2003-05-01 312389 #> 138 2003-06-01 300998 #> 139 2003-07-01 309923 #> 140 2003-08-01 317056 #> 141 2003-09-01 293890 #> 142 2003-10-01 304036 #> 143 2003-11-01 301265 #> 144 2003-12-01 357577 #> 145 2004-01-01 281460 #> 146 2004-02-01 282444 #> 147 2004-03-01 319077 #> 148 2004-04-01 315191 #> 149 2004-05-01 328408 #> 150 2004-06-01 321044 #> 151 2004-07-01 328000 #> 152 2004-08-01 326317 #> 153 2004-09-01 313524 #> 154 2004-10-01 319726 #> 155 2004-11-01 324259 #> 156 2004-12-01 387155 #> 157 2005-01-01 293261 #> 158 2005-02-01 295062 #> 159 2005-03-01 339141 #> 160 2005-04-01 335632 #> 161 2005-05-01 345348 #> 162 2005-06-01 350945 #> 163 2005-07-01 351827 #> 164 2005-08-01 355701 #> 165 2005-09-01 333289 #> 166 2005-10-01 336134 #> 167 2005-11-01 343798 #> 168 2005-12-01 405608 #> 169 2006-01-01 318546 #> 170 2006-02-01 314051 #> 171 2006-03-01 361993 #> 172 2006-04-01 351667 #> 173 2006-05-01 373560 #> 174 2006-06-01 366615 #> 175 2006-07-01 362203 #> 176 2006-08-01 375795 #> 177 2006-09-01 346214 #> 178 2006-10-01 348796 #> 179 2006-11-01 356928 #> 180 2006-12-01 417991 #> 181 2007-01-01 328877 #> 182 2007-02-01 323162 #> 183 2007-03-01 374142 #> 184 2007-04-01 358535 #> 185 2007-05-01 391512 #> 186 2007-06-01 376639 #> 187 2007-07-01 372354 #> 188 2007-08-01 388016 #> 189 2007-09-01 353936 #> 190 2007-10-01 368681 #> 191 2007-11-01 377802 #> 192 2007-12-01 426077 #> 193 2008-01-01 342697 #> 194 2008-02-01 343937 #> 195 2008-03-01 372923 #> 196 2008-04-01 368923 #> 197 2008-05-01 397969 #> 198 2008-06-01 378490 #> 199 2008-07-01 383686 #> 200 2008-08-01 382852 #> 201 2008-09-01 350560 #> 202 2008-10-01 349884 #> 203 2008-11-01 335571 #> 204 2008-12-01 384286 #> 205 2009-01-01 310269 #> 206 2009-02-01 299488 #> 207 2009-03-01 328568 #> 208 2009-04-01 329866 #> 209 2009-05-01 347768 #> 210 2009-06-01 344439 #> 211 2009-07-01 348106 #> 212 2009-08-01 353473 #> 213 2009-09-01 324708 #> 214 2009-10-01 338630 #> 215 2009-11-01 339386 #> 216 2009-12-01 400264 #> 217 2010-01-01 314640 #> 218 2010-02-01 311022 #> 219 2010-03-01 360819 #> 220 2010-04-01 356460 #> 221 2010-05-01 365713 #> 222 2010-06-01 358675 #> 223 2010-07-01 362027 #> 224 2010-08-01 362682 #> 225 2010-09-01 346069 #> 226 2010-10-01 355212 #> 227 2010-11-01 365809 #> 228 2010-12-01 426654 #> 229 2011-01-01 335608 #> 230 2011-02-01 337352 #> 231 2011-03-01 387092 #> 232 2011-04-01 380754 #> 233 2011-05-01 391970 #> 234 2011-06-01 388636 #> 235 2011-07-01 384600 #> 236 2011-08-01 394548 #> 237 2011-09-01 374895 #> 238 2011-10-01 379364 #> 239 2011-11-01 391081 #> 240 2011-12-01 451669 #> 241 2012-01-01 355058 #> 242 2012-02-01 372523 #> 243 2012-03-01 414275 #> 244 2012-04-01 393035 #> 245 2012-05-01 418648 #> 246 2012-06-01 400996 #> 247 2012-07-01 396020 #> 248 2012-08-01 417911 #> 249 2012-09-01 385597 #> 250 2012-10-01 399341 #> 251 2012-11-01 410992 #> 252 2012-12-01 461994 #> 253 2013-01-01 375537 #> 254 2013-02-01 373938 #> 255 2013-03-01 421638 #> 256 2013-04-01 408381 #> 257 2013-05-01 436985 #> 258 2013-06-01 414701 #> 259 2013-07-01 422357 #> 260 2013-08-01 434950 #> 261 2013-09-01 396199 #> 262 2013-10-01 415740 #> 263 2013-11-01 423611 #> 264 2013-12-01 477205 #> 265 2014-01-01 383399 #> 266 2014-02-01 380315 #> 267 2014-03-01 432806 #> 268 2014-04-01 431415 #> 269 2014-05-01 458822 #> 270 2014-06-01 433152 #> 271 2014-07-01 443005 #> 272 2014-08-01 450913 #> 273 2014-09-01 420871 #> 274 2014-10-01 437702 #> 275 2014-11-01 437910 #> 276 2014-12-01 501232 #> 277 2015-01-01 397252 #> 278 2015-02-01 386935 #> 279 2015-03-01 444110 #> 280 2015-04-01 438217 #> 281 2015-05-01 462615 #> 282 2015-06-01 448229 #> 283 2015-07-01 457710 #> 284 2015-08-01 456340 #> 285 2015-09-01 430917 #> 286 2015-10-01 444959 #> 287 2015-11-01 444507 #> 288 2015-12-01 518253 #> 289 2016-01-01 400928 #> 290 2016-02-01 413554 #> 291 2016-03-01 460093 #> 292 2016-04-01 450935 #> 293 2016-05-01 471421