STILL EXPERIMENTAL. THIS MAY NOT WORK AS ANTICIPATED.
lhs %C% rhs
| lhs | A value or the magrittr placeholder. |
|---|---|
| rhs | A function call using the magrittr semantics. |
This pipe can only be used at the start of a pipe chain, and must
be preceded by Cache(...) to allow other Cache arguments to be passed.
This will take the input arguments of the
first function immediately following the Cache() %C% and the
entire pipe chain code, evaluate them both
against the cacheRepo argument in Cache. If they exist, then
the entire pipe chain will be skipped, and only the previous final result
will be given. If there is no previous cached copy of the initial function's
arguments, then all chain elements will be evaluated. The final result will
be cached for future use. The entire chain must be identical, therefore.
The required usage should be straight forward to insert into existing code
that uses pipes (Cache() %C% ... remaining pipes.
This is still experimental; use with care.
pipe2
# dontrun{ # these can't be automatically run due to package conflicts with magrittr tmpdir <- file.path(tempdir(), "testCache") checkPath(tmpdir, create = TRUE)#> [1] "/tmp/RtmpzknuyG/testCache"a <- rnorm(10, 16) %>% mean() %>% prod(., 6) b <- Cache(cacheRepo = tmpdir) %C% # use of the %C% pipe! rnorm(10, 16) %>% mean() %>% prod(., 6) d <- Cache(cacheRepo = tmpdir) %C% rnorm(10, 16) %>% mean() %>% prod(., 6)#>e <- Cache(cacheRepo = tmpdir) %C% rnorm(10, 16) %>% mean() %>% prod(., 5) # changed all.equal(b,d) # TRUE#> [1] TRUEall.equal(a,d) # different because 'a' uses a unique rnorm, 'd' uses the Cached rnorm#> [1] "Mean relative difference: 4.957884"# because the arguments to rnorm, i.e., 10 and 16, and # the subsequent functions in the chain, are identical all.equal(a,e) # different because the final function, prod, has a changed argument.#> [1] "Mean relative difference: 3.132421"unlink(tmpdir, recursive = TRUE) #}