/
cache.html
731 lines (648 loc) · 50.6 KB
/
cache.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cache method that accommodates environments, S4 methods, Rasters, & nested caching — Cache • reproducible</title>
<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous" />
<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>
<!-- headroom.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>
<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>
<meta property="og:title" content="Cache method that accommodates environments, S4 methods, Rasters, & nested caching — Cache" />
<meta property="og:description" content="Still experimental and may change. This form cannot pass any arguments to
]codeCache, such as cacheRepo, thus it is of limited utility. However,
it is a clean alternative for simple cases." />
<meta name="twitter:card" content="summary" />
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-58633549-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-58633549-5');
</script>
</head>
<body>
<div class="container template-reference-topic">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">reproducible</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.0.0</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fas fa fas fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/Cache-using-postgresql.html">Using alternate database backends for Cache</a>
</li>
<li>
<a href="../articles/Intro-to-Cache.html">Introduction to Cache</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/PredictiveEcology/reproducible">
<span class="fab fa fab fa-github fa-lg"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Cache method that accommodates environments, S4 methods, Rasters, & nested caching</h1>
<small class="dont-index">Source: <a href='https://github.com/PredictiveEcology/reproducible/blob/master/R/cache.R'><code>R/cache.R</code></a>, <a href='https://github.com/PredictiveEcology/reproducible/blob/master/R/pipe.R'><code>R/pipe.R</code></a></small>
<div class="hidden name"><code>cache.Rd</code></div>
</div>
<div class="ref-description">
<p>Still experimental and may change. This form cannot pass any arguments to
]codeCache, such as <code>cacheRepo</code>, thus it is of limited utility. However,
it is a clean alternative for simple cases.</p>
</div>
<pre class="usage"><span class='fu'>Cache</span>(
<span class='no'>FUN</span>,
<span class='no'>...</span>,
<span class='kw'>notOlderThan</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>.objects</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>outputObjects</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>algo</span> <span class='kw'>=</span> <span class='st'>"xxhash64"</span>,
<span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>length</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.length"</span>, <span class='fl'>Inf</span>),
<span class='no'>compareRasterFileLength</span>,
<span class='kw'>userTags</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(),
<span class='no'>digestPathContent</span>,
<span class='kw'>omitArgs</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>classOptions</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span>(),
<span class='kw'>debugCache</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/character.html'>character</a></span>(),
<span class='kw'>sideEffect</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>makeCopy</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>quick</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.quick"</span>, <span class='fl'>FALSE</span>),
<span class='kw'>verbose</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.verbose"</span>, <span class='fl'>0</span>),
<span class='kw'>cacheId</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>useCache</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.useCache"</span>, <span class='fl'>TRUE</span>),
<span class='kw'>useCloud</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>cloudFolderID</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.cloudFolderID"</span>, <span class='kw'>NULL</span>),
<span class='kw'>showSimilar</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.showSimilar"</span>, <span class='fl'>FALSE</span>),
<span class='kw'>drv</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.drv"</span>, <span class='kw pkg'>RSQLite</span><span class='kw ns'>::</span><span class='fu'><a href='https://rsqlite.r-dbi.org/reference/SQLite.html'>SQLite</a></span>()),
<span class='kw'>conn</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.conn"</span>, <span class='kw'>NULL</span>)
)
<span class='co'># S4 method for ANY</span>
<span class='fu'>Cache</span>(
<span class='no'>FUN</span>,
<span class='no'>...</span>,
<span class='kw'>notOlderThan</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>.objects</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>outputObjects</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>algo</span> <span class='kw'>=</span> <span class='st'>"xxhash64"</span>,
<span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>length</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.length"</span>, <span class='fl'>Inf</span>),
<span class='no'>compareRasterFileLength</span>,
<span class='kw'>userTags</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(),
<span class='no'>digestPathContent</span>,
<span class='kw'>omitArgs</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>classOptions</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span>(),
<span class='kw'>debugCache</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/character.html'>character</a></span>(),
<span class='kw'>sideEffect</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>makeCopy</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>quick</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.quick"</span>, <span class='fl'>FALSE</span>),
<span class='kw'>verbose</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.verbose"</span>, <span class='fl'>0</span>),
<span class='kw'>cacheId</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
<span class='kw'>useCache</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.useCache"</span>, <span class='fl'>TRUE</span>),
<span class='kw'>useCloud</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>cloudFolderID</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.cloudFolderID"</span>, <span class='kw'>NULL</span>),
<span class='kw'>showSimilar</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.showSimilar"</span>, <span class='fl'>FALSE</span>),
<span class='kw'>drv</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.drv"</span>, <span class='kw pkg'>RSQLite</span><span class='kw ns'>::</span><span class='fu'><a href='https://rsqlite.r-dbi.org/reference/SQLite.html'>SQLite</a></span>()),
<span class='kw'>conn</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>getOption</a></span>(<span class='st'>"reproducible.conn"</span>, <span class='kw'>NULL</span>)
)
<span class='no'>lhs</span> <span class='kw'>%<%</span> <span class='no'>rhs</span></pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>FUN</th>
<td><p>Either a function or an unevaluated function call (e.g., using
<code>quote</code>.</p></td>
</tr>
<tr>
<th>...</th>
<td><p>Arguments passed to <code>FUN</code></p></td>
</tr>
<tr>
<th>notOlderThan</th>
<td><p>A time. Load an object from the Cache if it was created after this.</p></td>
</tr>
<tr>
<th>.objects</th>
<td><p>Character vector of objects to be digested. This is only applicable
if there is a list, environment (or similar) named objects
within it. Only this/these objects will be considered for caching,
i.e., only use a subset of
the list, environment or similar objects.</p></td>
</tr>
<tr>
<th>outputObjects</th>
<td><p>Optional character vector indicating which objects to
return. This is only relevant for list, environment (or similar) objects</p></td>
</tr>
<tr>
<th>algo</th>
<td><p>The algorithms to be used; currently available choices are
<code>md5</code>, which is also the default, <code>sha1</code>, <code>crc32</code>,
<code>sha256</code>, <code>sha512</code>, <code>xxhash32</code>, <code>xxhash64</code>,
<code>murmur32</code> and <code>spookyhash</code>.</p></td>
</tr>
<tr>
<th>cacheRepo</th>
<td><p>A repository used for storing cached objects.
This is optional if <code>Cache</code> is used inside a SpaDES module.</p></td>
</tr>
<tr>
<th>length</th>
<td><p>Numeric. If the element passed to Cache is a <code>Path</code> class
object (from e.g., <code><a href='Path-class.html'>asPath(filename)</a></code>) or it is a <code>Raster</code> with
file-backing, then this will be
passed to <code><a href='https://rdrr.io/pkg/digest/man/digest.html'>digest::digest</a></code>, essentially limiting the number of bytes
to digest (for speed). This will only be used if <code>quick = FALSE</code>.
Default is <code><a href='https://rdrr.io/r/base/options.html'>getOption("reproducible.length")</a></code>,
which is set to <code>Inf</code>.</p></td>
</tr>
<tr>
<th>compareRasterFileLength</th>
<td><p>Being deprecated; use <code>length</code>.</p></td>
</tr>
<tr>
<th>userTags</th>
<td><p>A character vector with descriptions of the Cache function call. These
will be added to the Cache so that this entry in the Cache can be found using
<code>userTags</code> e.g., via <code><a href='viewCache.html'>showCache</a></code></p></td>
</tr>
<tr>
<th>digestPathContent</th>
<td><p>Being deprecated. Use <code>quick</code>.</p></td>
</tr>
<tr>
<th>omitArgs</th>
<td><p>Optional character string of arguments in the FUN to omit from the digest.</p></td>
</tr>
<tr>
<th>classOptions</th>
<td><p>Optional list. This will pass into <code>.robustDigest</code> for
specific classes. Should be options that the <code>.robustDigest</code> knows what
to do with.</p></td>
</tr>
<tr>
<th>debugCache</th>
<td><p>Character or Logical. Either <code>"complete"</code> or <code>"quick"</code> (uses
partial matching, so "c" or "q" work). <code>TRUE</code> is
equivalent to <code>"complete"</code>.
If <code>"complete"</code>, then the returned object from the Cache
function will have two attributes, <code>debugCache1</code> and <code>debugCache2</code>,
which are the entire <code><a href='https://rdrr.io/r/base/list.html'>list(...)</a></code> and that same object, but after all
<code>.robustDigest</code> calls, at the moment that it is digested using
<code>digest</code>, respectively. This <code><a href='https://rdrr.io/r/base/attr.html'>attr(mySimOut, "debugCache2")</a></code>
can then be compared to a subsequent call and individual items within
the object <code><a href='https://rdrr.io/r/base/attr.html'>attr(mySimOut, "debugCache1")</a></code> can be compared.
If <code>"quick"</code>, then it will return the same two objects directly,
without evalutating the <code>FUN(...)</code>.</p></td>
</tr>
<tr>
<th>sideEffect</th>
<td><p>Logical or path. Determines where the function will look for
new files following function completion. See Details.
<em>NOTE: this argument is experimental and may change in future releases.</em></p></td>
</tr>
<tr>
<th>makeCopy</th>
<td><p>Logical. If <code>sideEffect = TRUE</code>, and <code>makeCopy = TRUE</code>,
a copy of the downloaded files will be made and stored in the <code>cacheRepo</code>
to speed up subsequent file recovery in the case where the original copy
of the downloaded files are corrupted or missing. Currently only works when
set to <code>TRUE</code> during the first run of <code>Cache</code>. Default is <code>FALSE</code>.
<em>NOTE: this argument is experimental and may change in future releases.</em></p></td>
</tr>
<tr>
<th>quick</th>
<td><p>Logical. If <code>TRUE</code>,
little or no disk-based information will be assessed, i.e., mostly its
memory content. This is relevant for objects of class <code>character</code>,
<code>Path</code> and <code>Raster</code> currently. For class <code>character</code>, it is ambiguous
whether this represents a character string or a vector of file paths. The function
will assess if it is a path to a file or directory first. If not, it will treat
the object as a character string. If it is known that character strings should
not be treated as paths, then <code>quick = TRUE</code> will be much faster, with no loss
of information. If it is file or directory, then it will digest the file content,
or <code><a href='https://rdrr.io/r/base/basename.html'>basename(object)</a></code>. For class <code>Path</code> objects, the file's metadata
(i.e., filename and file size)
will be hashed instead of the file contents if <code>quick = TRUE</code>.
If set to <code>FALSE</code> (default),
the contents of the file(s) are hashed.
If <code>quick = TRUE</code>, <code>length</code> is ignored. <code>Raster</code> objects are treated
as paths, if they are file-backed.</p></td>
</tr>
<tr>
<th>verbose</th>
<td><p>Numeric, with 0 being off, 1 being a little, 2 being more verbose etc.
Above 1 will output much more information about the internals of
Caching, which may help diagnose Caching challenges.</p></td>
</tr>
<tr>
<th>cacheId</th>
<td><p>Character string. If passed, this will override the calculated hash
of the inputs, and return the result from this cacheId in the cacheRepo.
Setting this is equivalent to manually saving the output of this function, i.e.,
the object will be on disk, and will be recovered in subsequent
This may help in some particularly finicky situations
where Cache is not correctly detecting unchanged inputs. This will guarantee
the object will be identical each time; this may be useful in operational code.</p></td>
</tr>
<tr>
<th>useCache</th>
<td><p>Logical, numeric or <code>"overwrite"</code> or <code>"devMode"</code>. See details.</p></td>
</tr>
<tr>
<th>useCloud</th>
<td><p>Logical. See Details.</p></td>
</tr>
<tr>
<th>cloudFolderID</th>
<td><p>A googledrive dribble of a folder, e.g., using <code>drive_mkdir()</code>.
If left as <code>NULL</code>, the function will create a cloud folder with name from last
two folder levels of the <code>cacheRepo</code> path, :
<code><a href='https://rdrr.io/r/base/paste.html'>paste0(basename(dirname(cacheRepo)), "_", basename(cacheRepo))</a></code>.
This <code>cloudFolderID</code> will be added to <code><a href='https://rdrr.io/r/base/options.html'>options("reproducible.cloudFolderID")</a></code>,
but this will not persist across sessions. If this is a character string, it will
treat this as a folder name to create or use on GoogleDrive.</p></td>
</tr>
<tr>
<th>showSimilar</th>
<td><p>A logical or numeric. Useful for debugging.
If <code>TRUE</code> or <code>1</code>, then if the Cache
does not find an identical archive in the cacheRepo, it will report (via message)
the next most similar archive, and indicate which argument(s) is/are different.
If a number larger than <code>1</code>, then it will report the N most similar archived
objects.</p></td>
</tr>
<tr>
<th>drv</th>
<td><p>an object that inherits from DBIDriver,
or an existing DBIConnection
object (in order to clone an existing connection).</p></td>
</tr>
<tr>
<th>conn</th>
<td><p>A DBIConnection object, as returned by
<code><a href='https://dbi.r-dbi.org/reference/dbConnect.html'>dbConnect()</a></code>.</p></td>
</tr>
<tr>
<th>lhs</th>
<td><p>A name to assign to.</p></td>
</tr>
<tr>
<th>rhs</th>
<td><p>A function call</p></td>
</tr>
</table>
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
<p>As with <code><a href='https://rdrr.io/pkg/archivist/man/cache.html'>archivist::cache</a></code>, returns the value of the
function call or the cached version (i.e., the result from a previous call
to this same cached function with identical arguments).</p>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>Caching R objects using <code><a href='https://rdrr.io/pkg/archivist/man/cache.html'>archivist::cache</a></code> has five important limitations:</p><ol>
<li><p>the <code>archivist</code> package detects different environments as different;</p></li>
<li><p>it also does not detect S4 methods correctly due to method inheritance;</p></li>
<li><p>it does not detect objects that have file-base storage of information
(specifically <code><a href='https://rdrr.io/pkg/raster/man/Raster-classes.html'>RasterLayer-class</a></code> objects);</p></li>
<li><p>the default hashing algorithm is relatively slow.</p></li>
<li><p>heavily nested function calls may want Cache arguments to propagate through</p></li>
</ol><p>This version of the <code>Cache</code> function accommodates those four special,
though quite common, cases by:</p><ol>
<li><p>converting any environments into list equivalents;</p></li>
<li><p>identifying the dispatched S4 method (including those made through
inheritance) before hashing so the correct method is being cached;</p></li>
<li><p>by hashing the linked file, rather than the Raster object.
Currently, only file-backed <code>Raster*</code> objects are digested
(e.g., not <code>ff</code> objects, or any other R object where the data
are on disk instead of in RAM);</p></li>
<li><p>Uses <code><a href='https://rdrr.io/pkg/digest/man/digest.html'>digest</a></code> (formerly fastdigest, which does
not translate between operating systems).
This is used for file-backed objects as well.</p></li>
<li><p>Cache will save arguments passed by user in a hidden environment. Any
nested Cache functions will use arguments in this order 1) actual arguments
passed at each Cache call, 2) any inherited arguments from an outer Cache
call, 3) the default values of the Cache function. See section on <em>Nested
Caching</em>.</p></li>
</ol>
<p>If <code>Cache</code> is called within a SpaDES module, then the cached entry will automatically
get 3 extra <code>userTags</code>: <code>eventTime</code>, <code>eventType</code>, and <code>moduleName</code>.
These can then be used in <code>clearCache</code> to selectively remove cached objects
by <code>eventTime</code>, <code>eventType</code> or <code>moduleName</code>.</p>
<p><code>Cache</code> will add a tag to the artifact in the database called <code>accessed</code>,
which will assign the time that it was accessed, either read or write.
That way, artifacts can be shown (using <code>showCache</code>) or removed (using
<code>clearCache</code>) selectively, based on their access dates, rather than only
by their creation dates. See example in <code><a href='viewCache.html'>clearCache</a></code>.
<code>Cache</code> (uppercase C) is used here so that it is not confused with, and does
not mask, the <code><a href='https://rdrr.io/pkg/archivist/man/cache.html'>archivist::cache</a></code> function.</p>
<h2 class="hasAnchor" id="note"><a class="anchor" href="#note"></a>Note</h2>
<p>As indicated above, several objects require pre-treatment before
caching will work as expected. The function <code>.robustDigest</code> accommodates this.
It is an S4 generic, meaning that developers can produce their own methods for
different classes of objects. Currently, there are methods for several types
of classes. See <code><a href='robustDigest.html'>.robustDigest</a></code>.</p>
<p>See <code><a href='robustDigest.html'>.robustDigest</a></code> for other specifics for other classes.</p>
<h2 class="hasAnchor" id="nested-caching"><a class="anchor" href="#nested-caching"></a>Nested Caching</h2>
<p>Commonly, Caching is nested, i.e., an outer function is wrapped in a <code>Cache</code>
function call, and one or more inner functions are also wrapped in a <code>Cache</code>
function call. A user <em>can</em> always specify arguments in every Cache function
call, but this can get tedious and can be prone to errors. The normal way that
<em>R</em> handles arguments is it takes the user passed arguments if any, and
default arguments for all those that have no user passed arguments. We have inserted
a middle step. The order or precedence for any given <code>Cache</code> function call is
1. user arguments, 2. inherited arguments, 3. default arguments. At this time,
the top level <code>Cache</code> arguments will propagate to all inner functions unless
each individual <code>Cache</code> call has other arguments specified, i.e., "middle"
nested <code>Cache</code> function calls don't propagate their arguments to further "inner"
<code>Cache</code> function calls. See example.</p>
<p><code>userTags</code> is unique of all arguments: its values will be appended to the
inherited <code>userTags</code>.</p>
<h2 class="hasAnchor" id="caching-speed"><a class="anchor" href="#caching-speed"></a>Caching Speed</h2>
<p>Caching speed may become a critical aspect of a final product. For example,
if the final product is a shiny app, rerunning the entire project may need
to take less then a few seconds at most. There are 3 arguments that affect
Cache speed: <code>quick</code>, <code>length</code>, and
<code>algo</code>. <code>quick</code> is passed to <code>.robustDigest</code>, which currently
only affects <code>Path</code> and <code>Raster*</code> class objects. In both cases, <code>quick</code>
means that little or no disk-based information will be assessed.</p>
<h2 class="hasAnchor" id="filepaths"><a class="anchor" href="#filepaths"></a>Filepaths</h2>
<p>If a function has a path argument, there is some ambiguity about what should be
done. Possibilities include:</p><ol>
<li><p>hash the string as is (this will be very system specific, meaning a
<code>Cache</code> call will not work if copied between systems or directories);</p></li>
<li><p>hash the <code><a href='https://rdrr.io/r/base/basename.html'>basename(path)</a></code>;</p></li>
<li><p>hash the contents of the file.</p></li>
</ol><p>If paths are passed in as is (i.e,. character string), the result will not be predictable.
Instead, one should use the wrapper function <code><a href='Path-class.html'>asPath(path)</a></code>, which sets the
class of the string to a <code>Path</code>, and one should decide whether one wants
to digest the content of the file (using <code>quick = FALSE</code>),
or just the filename (<code>(quick = TRUE)</code>). See examples.</p>
<h2 class="hasAnchor" id="stochasticity"><a class="anchor" href="#stochasticity"></a>Stochasticity</h2>
<p>In general, it is expected that caching will only be used when stochasticity
is not relevant, or if a user has achieved sufficient stochasticity (e.g., via
sufficient number of calls to <code>experiment</code>) such that no new explorations
of stochastic outcomes are required. It will also be very useful in a
reproducible workflow.</p>
<h2 class="hasAnchor" id="usecache"><a class="anchor" href="#usecache"></a>useCache</h2>
<p>Logical or numeric. If <code>FALSE</code> or <code>0</code>, then the entire Caching
mechanism is bypassed and the
function is evaluated as if it was not being Cached. Default is
<code><a href='https://rdrr.io/r/base/options.html'>getOption("reproducible.useCache")</a></code>), which is <code>TRUE</code> by default,
meaning use the Cache mechanism. This may be useful to turn all Caching on or
off in very complex scripts and nested functions. Increasing levels of numeric
values will cause deeper levels of Caching to occur. Currently, only implemented
in <code>postProcess</code>: to do both caching of inner <code>cropInputs</code>, <code>projectInputs</code>
and <code>maskInputs</code>, and caching of outer <code>postProcess</code>, use
<code>useCache = 2</code>; to skip the inner sequence of 3 functions, use <code>useCache = 1</code>.
For large objects, this may prevent many duplicated save to disk events.</p>
<p>If <code>"overwrite"</code>
(which can be set with <code><a href='https://rdrr.io/r/base/options.html'>options("reproducible.useCache" =
"overwrite")</a></code>), then the function invoke the caching mechanism but will purge
any entry that is matched, and it will be replaced with the results of the
current call.</p>
<p>If <code>"devMode"</code>: The point of this mode is to facilitate using the Cache when
functions and datasets are continually in flux, and old Cache entries are
likely stale very often. In `devMode`, the cache mechanism will work as
normal if the Cache call is the first time for a function OR if it
successfully finds a copy in the cache based on the normal Cache mechanism.
It *differs* from the normal Cache if the Cache call does *not* find a copy
in the `cacheRepo`, but it does find an entry that matches based on
`userTags`. In this case, it will delete the old entry in the `cacheRepo`
(identified based on matching `userTags`), then continue with normal `Cache`.
For this to work correctly, `userTags` must be unique for each function call.
This should be used with caution as it is still experimental. Currently, if
<code>userTags</code> are not unique to a single entry in the cacheRepo, it will
default to the behaviour of <code>useCache = TRUE</code> with a message. This means
that <code>"devMode"</code> is most useful if used from the start of a project.</p>
<h2 class="hasAnchor" id="usecloud"><a class="anchor" href="#usecloud"></a><code>useCloud</code></h2>
<p>This is a way to store all or some of the local Cache in the cloud.
Currently, the only cloud option is Google Drive, via <code>googledrive</code>
package. For this to work, the user must be or be able to be authenticated
with <code><a href='https://googledrive.tidyverse.org/reference/drive_auth.html'>googledrive::drive_auth</a></code>. The principle behind this
<code>useCloud</code> is that it will be a full or partial mirror of a local Cache.
It is not intended to be used independently from a local Cache. To share
objects that are in the Cloud with another person, it requires 2 steps. 1)
share the <code>cloudFolderID$id</code>, which can be retrieved by
<code>getOption("reproducible.cloudFolderID")$id</code> after at least one Cache
call has been made. 2) The other user must then set their
<code>cacheFolderID</code> in a
<code>Cache\(..., reproducible.cloudFolderID = \"the ID here\"\)</code> call or
set their option manually
<code>options\(\"reproducible.cloudFolderID\" = \"the ID here\"\)</code>.</p>
<p>If <code>TRUE</code>, then this Cache call will download
(if local copy doesn't exist, but cloud copy does exist), upload
(local copy does or doesn't exist and
cloud copy doesn't exist), or
will not download nor upload if object exists in both. If <code>TRUE</code> will be at
least 1 second slower than setting this to <code>FALSE</code>, and likely even slower as the
cloud folder gets large. If a user wishes to keep "high-level" control, set this to
<code><a href='https://rdrr.io/r/base/options.html'>getOption("reproducible.useCloud", FALSE)</a></code> or
<code><a href='https://rdrr.io/r/base/options.html'>getOption("reproducible.useCloud", TRUE)</a></code> (if the default behaviour should
be <code>FALSE</code> or <code>TRUE</code>, respectively) so it can be turned on and off with
this option. NOTE: <em>This argument will not be passed into inner/nested Cache calls.</em>)</p>
<h2 class="hasAnchor" id="sideeffect"><a class="anchor" href="#sideeffect"></a><code>sideEffect</code></h2>
<p>If <code>sideEffect</code> is not <code>FALSE</code>, then metadata about any files that
added to <code>sideEffect</code> will be added as an attribute to the cached copy.
Subsequent calls to this function
will assess for the presence of the new files in the <code>sideEffect</code> location.
If the files are identical (<code>quick = FALSE</code>) or their file size is
identical (<code>quick = TRUE</code>), then the cached copy of the function will
be returned (and no files changed). If there are missing or incorrect files,
then the function will re-run. This will accommodate the situation where the
function call is identical, but somehow the side effect files were modified.
If <code>sideEffect</code> is logical, then the function will check the
<code>cacheRepo</code>; if it is a path, then it will check the path. The function will
assess whether the files to be downloaded are found locally
prior to download. If it fails the local test, then it will try to recover from a
local copy if (<code>makeCopy</code> had been set to <code>TRUE</code> the first time
the function was run. Currently, local recovery will only work if<code>makeCOpy</code> was
set to <code>TRUE</code> the first time <code>Cache</code>
was run). Default is <code>FALSE</code>.</p>
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><code><a href='https://rdrr.io/pkg/archivist/man/cache.html'>archivist::cache</a></code>, <code><a href='robustDigest.html'>.robustDigest</a></code></p></div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><div class='input'><span class='no'>tmpDir</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/file.path.html'>file.path</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/tempfile.html'>tempdir</a></span>())
<span class='co'># Basic use</span>
<span class='no'>ranNumsA</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>rnorm</span>, <span class='fl'>10</span>, <span class='fl'>16</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>)
<span class='co'># All same</span>
<span class='no'>ranNumsB</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>rnorm</span>, <span class='fl'>10</span>, <span class='fl'>16</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>) <span class='co'># recovers cached copy</span></div><div class='output co'>#> <span class='message'><span style='color: #0000BB;'> loading cached result from previous rnorm call.</span><span></span></div><div class='input'><span class='no'>ranNumsC</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>) <span class='kw'>%C%</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='fl'>10</span>, <span class='fl'>16</span>) <span class='co'># recovers cached copy</span></div><div class='output co'>#> <span class='error'>Error in match.call(definition, call, expand.dots, envir): unused argument (envir = <environment>)</span></div><div class='input'><span class='no'>ranNumsD</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='fu'><a href='https://rdrr.io/r/base/substitute.html'>quote</a></span>(<span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='kw'>n</span> <span class='kw'>=</span> <span class='fl'>10</span>, <span class='fl'>16</span>)), <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>) <span class='co'># recovers cached copy</span></div><div class='output co'>#> <span class='message'></span><span style='color: #0000BB;'> loading cached result from previous rnorm call.</span><span></span></div><div class='input'>
<span class='co'>###############################################</span>
<span class='co'># experimental devMode</span>
<span class='co'>###############################################</span>
<span class='no'>opt</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/options.html'>options</a></span>(<span class='st'>"reproducible.useCache"</span> <span class='kw'>=</span> <span class='st'>"devMode"</span>)
<span class='fu'><a href='viewCache.html'>clearCache</a></span>(<span class='no'>tmpDir</span>, <span class='kw'>ask</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
<span class='no'>centralTendency</span> <span class='kw'><-</span> <span class='kw'>function</span>(<span class='no'>x</span>)
<span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span>(<span class='no'>x</span>)
<span class='no'>funnyData</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>1</span>, <span class='fl'>1</span>, <span class='fl'>1</span>, <span class='fl'>1</span>, <span class='fl'>10</span>)
<span class='no'>uniqueUserTags</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"thisIsUnique"</span>, <span class='st'>"reallyUnique"</span>)
<span class='no'>ranNumsB</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>centralTendency</span>, <span class='no'>funnyData</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>,
<span class='kw'>userTags</span> <span class='kw'>=</span> <span class='no'>uniqueUserTags</span>) <span class='co'># sets new value to Cache</span>
<span class='fu'><a href='viewCache.html'>showCache</a></span>(<span class='no'>tmpDir</span>) <span class='co'># 1 unique artifact -- cacheId is 8be9cf2a072bdbb0515c5f0b3578f474</span></div><div class='output co'>#> <span class='message'>Cache size: </span></div><div class='output co'>#> <span class='message'> Total (including Rasters): 246 bytes</span></div><div class='output co'>#> <span class='message'> Selected objects (not including Rasters): 246 bytes</span></div><div class='output co'>#> cacheId tagKey tagValue createdDate
#> 1: 71cd24ec3b0d0cac thisIsUnique thisIsUnique 2020-02-19 16:38:17
#> 2: 71cd24ec3b0d0cac reallyUnique reallyUnique 2020-02-19 16:38:17
#> 3: 71cd24ec3b0d0cac function centralTendency 2020-02-19 16:38:17
#> 4: 71cd24ec3b0d0cac class numeric 2020-02-19 16:38:17
#> 5: 71cd24ec3b0d0cac object.size 984 2020-02-19 16:38:17
#> 6: 71cd24ec3b0d0cac accessed 2020-02-19 16:38:16 2020-02-19 16:38:17
#> 7: 71cd24ec3b0d0cac inCloud FALSE 2020-02-19 16:38:17
#> 8: 71cd24ec3b0d0cac otherFunctions saveRDS 2020-02-19 16:38:17
#> 9: 71cd24ec3b0d0cac otherFunctions do.call 2020-02-19 16:38:17
#> 10: 71cd24ec3b0d0cac otherFunctions build_site_local 2020-02-19 16:38:17
#> 11: 71cd24ec3b0d0cac otherFunctions build_reference 2020-02-19 16:38:17
#> 12: 71cd24ec3b0d0cac otherFunctions data_reference_topic 2020-02-19 16:38:17
#> 13: 71cd24ec3b0d0cac otherFunctions run_examples 2020-02-19 16:38:17
#> 14: 71cd24ec3b0d0cac otherFunctions highlight_examples 2020-02-19 16:38:17
#> 15: 71cd24ec3b0d0cac otherFunctions timing_fn 2020-02-19 16:38:17
#> 16: 71cd24ec3b0d0cac otherFunctions handle 2020-02-19 16:38:17
#> 17: 71cd24ec3b0d0cac otherFunctions try 2020-02-19 16:38:17
#> 18: 71cd24ec3b0d0cac otherFunctions withVisible 2020-02-19 16:38:17
#> 19: 71cd24ec3b0d0cac preDigest x:e4aa8de28dc6c1bb 2020-02-19 16:38:17
#> 20: 71cd24ec3b0d0cac preDigest .FUN:d5f5f91cbb662db9 2020-02-19 16:38:17
#> 21: 71cd24ec3b0d0cac file.size 144 2020-02-19 16:38:17
#> cacheId tagKey tagValue createdDate</div><div class='input'>
<span class='co'># During development, we often redefine function internals</span>
<span class='no'>centralTendency</span> <span class='kw'><-</span> <span class='kw'>function</span>(<span class='no'>x</span>)
<span class='fu'><a href='https://rdrr.io/r/stats/median.html'>median</a></span>(<span class='no'>x</span>)
<span class='co'># When we rerun, we don't want to keep the "old" cache because the function will</span>
<span class='co'># never again be defined that way. Here, because of userTags being the same,</span>
<span class='co'># it will replace the entry in the Cache, effetively overwriting it, even though</span>
<span class='co'># it has a different cacheId</span>
<span class='no'>ranNumsD</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>centralTendency</span>, <span class='no'>funnyData</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>, <span class='kw'>userTags</span> <span class='kw'>=</span> <span class='no'>uniqueUserTags</span>)</div><div class='output co'>#> <span class='message'></span><span style='color: #00BBBB;'> ------ devMode -------</span><span></span></div><div class='output co'>#> <span class='message'></span><span style='color: #00BBBB;'>This call to cache will replace</span><span></span></div><div class='output co'>#> <span class='message'></span><span style='color: #00BBBB;'>... artifact with cacheId 71cd24ec3b0d0cac</span><span></span></div><div class='output co'>#> <span class='message'></span><span style='color: #00BBBB;'>... different .FUN</span><span></span></div><div class='output co'>#> <span class='message'></span><span style='color: #00BBBB;'> ------ end devMode -------</span><span></span></div><div class='output co'>#> <span class='message'>Overwriting Cache entry with userTags: 'thisIsUnique, reallyUnique, centralTendency'</span></div><div class='input'><span class='fu'><a href='viewCache.html'>showCache</a></span>(<span class='no'>tmpDir</span>) <span class='co'># 1 unique artifact -- cacheId is bb1195b40c8d37a60fd6004e5d526e6b</span></div><div class='output co'>#> <span class='message'>Cache size: </span></div><div class='output co'>#> <span class='message'> Total (including Rasters): 246 bytes</span></div><div class='output co'>#> <span class='message'> Selected objects (not including Rasters): 246 bytes</span></div><div class='output co'>#> cacheId tagKey tagValue createdDate
#> 1: 632cd06f30e111be thisIsUnique thisIsUnique 2020-02-19 16:38:17
#> 2: 632cd06f30e111be reallyUnique reallyUnique 2020-02-19 16:38:17
#> 3: 632cd06f30e111be function centralTendency 2020-02-19 16:38:17
#> 4: 632cd06f30e111be class numeric 2020-02-19 16:38:17
#> 5: 632cd06f30e111be object.size 984 2020-02-19 16:38:17
#> 6: 632cd06f30e111be accessed 2020-02-19 16:38:17 2020-02-19 16:38:17
#> 7: 632cd06f30e111be inCloud FALSE 2020-02-19 16:38:17
#> 8: 632cd06f30e111be otherFunctions saveRDS 2020-02-19 16:38:17
#> 9: 632cd06f30e111be otherFunctions do.call 2020-02-19 16:38:17
#> 10: 632cd06f30e111be otherFunctions build_site_local 2020-02-19 16:38:17
#> 11: 632cd06f30e111be otherFunctions build_reference 2020-02-19 16:38:17
#> 12: 632cd06f30e111be otherFunctions data_reference_topic 2020-02-19 16:38:17
#> 13: 632cd06f30e111be otherFunctions run_examples 2020-02-19 16:38:17
#> 14: 632cd06f30e111be otherFunctions highlight_examples 2020-02-19 16:38:17
#> 15: 632cd06f30e111be otherFunctions timing_fn 2020-02-19 16:38:17
#> 16: 632cd06f30e111be otherFunctions handle 2020-02-19 16:38:17
#> 17: 632cd06f30e111be otherFunctions try 2020-02-19 16:38:17
#> 18: 632cd06f30e111be otherFunctions withVisible 2020-02-19 16:38:17
#> 19: 632cd06f30e111be preDigest x:e4aa8de28dc6c1bb 2020-02-19 16:38:17
#> 20: 632cd06f30e111be preDigest .FUN:af11d20d957667d9 2020-02-19 16:38:17
#> 21: 632cd06f30e111be file.size 143 2020-02-19 16:38:17
#> cacheId tagKey tagValue createdDate</div><div class='input'>
<span class='co'># If it finds it by cacheID, doesn't matter what the userTags are</span>
<span class='no'>ranNumsD</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>centralTendency</span>, <span class='no'>funnyData</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='no'>tmpDir</span>, <span class='kw'>userTags</span> <span class='kw'>=</span> <span class='st'>"thisIsUnique"</span>)</div><div class='output co'>#> <span class='message'></span><span style='color: #0000BB;'> loading cached result from previous centralTendency call.</span><span></span></div><div class='input'>
<span class='fu'><a href='https://rdrr.io/r/base/options.html'>options</a></span>(<span class='no'>opt</span>)
<span class='co'># For more in depth uses, see vignette</span>
<span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
<span class='co'># To use Postgres, set environment variables with the required credentials</span>
<span class='kw'>if</span> (<span class='fu'><a href='https://rdrr.io/r/base/ns-load.html'>requireNamespace</a></span>(<span class='st'>"RPostgres"</span>)) {
<span class='fu'><a href='https://rdrr.io/r/base/Sys.setenv.html'>Sys.setenv</a></span>(<span class='kw'>PGHOST</span> <span class='kw'>=</span> <span class='st'>"server.url"</span>)
<span class='fu'><a href='https://rdrr.io/r/base/Sys.setenv.html'>Sys.setenv</a></span>(<span class='kw'>PGPORT</span> <span class='kw'>=</span> <span class='fl'>5432</span>)
<span class='fu'><a href='https://rdrr.io/r/base/Sys.setenv.html'>Sys.setenv</a></span>(<span class='kw'>PGDATABASE</span> <span class='kw'>=</span> <span class='st'>"mydatabase"</span>)
<span class='fu'><a href='https://rdrr.io/r/base/Sys.setenv.html'>Sys.setenv</a></span>(<span class='kw'>PGUSER</span> <span class='kw'>=</span> <span class='st'>"mydbuser"</span>)
<span class='fu'><a href='https://rdrr.io/r/base/Sys.setenv.html'>Sys.setenv</a></span>(<span class='kw'>PGPASSWORD</span> <span class='kw'>=</span> <span class='st'>"mysecurepassword"</span>)
<span class='no'>conn</span> <span class='kw'><-</span> <span class='kw pkg'>DBI</span><span class='kw ns'>::</span><span class='fu'><a href='https://dbi.r-dbi.org/reference/dbConnect.html'>dbConnect</a></span>(<span class='kw pkg'>RPostgres</span><span class='kw ns'>::</span><span class='fu'><a href='https://rpostgres.r-dbi.org/reference/Postgres.html'>Postgres</a></span>())
<span class='fu'><a href='https://rdrr.io/r/base/options.html'>options</a></span>(<span class='st'>"reproducible.conn"</span> <span class='kw'>=</span> <span class='no'>conn</span>)
<span class='co'># Will use postgres for cache data table, and tempdir() for saved R objects</span>
<span class='fu'>Cache</span>(<span class='no'>rnorm</span>, <span class='fl'>1</span>, <span class='kw'>cacheRepo</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/tempfile.html'>tempdir</a></span>())
}
<span class='fu'><a href='https://rdrr.io/r/utils/browseVignettes.html'>browseVignettes</a></span>(<span class='kw'>package</span> <span class='kw'>=</span> <span class='st'>"reproducible"</span>)
}
<span class='co'># Equivalent</span>
<span class='no'>a</span> <span class='kw'><-</span> <span class='fu'>Cache</span>(<span class='no'>rnorm</span>, <span class='fl'>1</span>)
<span class='no'>b</span> <span class='kw'>%<%</span> <span class='fu'><a href='https://rdrr.io/r/stats/Normal.html'>rnorm</a></span>(<span class='fl'>1</span>)</div><div class='output co'>#> <span class='message'></span><span style='color: #0000BB;'> loading cached result from previous rnorm call.</span><span></span></div><div class='input'>
</div></span></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#arguments">Arguments</a></li>
<li><a href="#value">Value</a></li>
<li><a href="#details">Details</a></li>
<li><a href="#note">Note</a></li>
<li><a href="#nested-caching">Nested Caching</a></li>
<li><a href="#caching-speed">Caching Speed</a></li>
<li><a href="#filepaths">Filepaths</a></li>
<li><a href="#stochasticity">Stochasticity</a></li>
<li><a href="#usecache">useCache</a></li>
<li><a href="#usecloud"><code>useCloud</code></a></li>
<li><a href="#sideeffect"><code>sideEffect</code></a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#examples">Examples</a></li>
</ul>
<h2>Author</h2>
<p>Eliot McIntire</p>
</div>
</div>
<footer>
<div class="copyright">
<p>Developed by Eliot J B McIntire, Alex M Chubaty.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p>
</div>
</footer>
</div>
</body>
</html>