# NOT RUN {
tmpdir <- file.path(tempdir(), "testCache")
checkPath(tmpdir, create = TRUE)
a <- rnorm(10, 16) %>%
mean() %>%
prod(., 6)
b <- Cache(cacheRepo = tmpdir) %C%
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
all.equal(a,d) # different because 'a' uses a unique rnorm, 'd' uses the Cached rnorm
# 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.
unlink(tmpdir, recursive = TRUE)
# }
Run the code above in your browser using DataLab