| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/cache.R |
| 3 |
\name{load_cache} |
| 4 |
\alias{load_cache} |
| 5 |
\title{Load the cache database of a code chunk} |
| 6 |
\usage{ |
| 7 |
load_cache( |
| 8 |
label, |
| 9 |
object, |
| 10 |
notfound = "NOT AVAILABLE", |
| 11 |
path = opts_chunk$get("cache.path"), |
| 12 |
dir = opts_knit$get("output.dir"), |
| 13 |
envir = NULL, |
| 14 |
lazy = TRUE |
| 15 |
) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{label}{The chunk label of the code chunk that has a cache database.} |
| 19 |
|
| 20 |
\item{object}{The name of the object to be fetched from the database. If it |
| 21 |
is missing, \code{NULL} is returned).} |
| 22 |
|
| 23 |
\item{notfound}{A value to use when the \code{object} cannot be found.} |
| 24 |
|
| 25 |
\item{path}{Path of the cache database (normally set in the global chunk |
| 26 |
option \code{cache.path}).} |
| 27 |
|
| 28 |
\item{dir}{Path to use as the working directory. Defaults to the output |
| 29 |
directory if run inside a \pkg{knitr} context and to the current working |
| 30 |
directory otherwise. Any relative \code{path} is defined from \code{dir}.} |
| 31 |
|
| 32 |
\item{envir}{Environment to use for cache loading, into which all objects in |
| 33 |
the cache for the specified chunk (not just that in \code{object}) will be |
| 34 |
loaded. Defaults to the value in \code{\link{knit_global}}.} |
| 35 |
|
| 36 |
\item{lazy}{Whether to \code{\link{lazyLoad}} the cache database (depending |
| 37 |
on the chunk option \code{cache.lazy = TRUE} or \code{FALSE} of that code |
| 38 |
chunk).} |
| 39 |
} |
| 40 |
\value{ |
| 41 |
Invisible \code{NULL} when \code{object} is not specified (the cache |
| 42 |
database will be loaded as a side effect), otherwise the value of the |
| 43 |
object if found. |
| 44 |
} |
| 45 |
\description{ |
| 46 |
If a code chunk has turned on the chunk option \code{cache = TRUE}, a cache |
| 47 |
database will be established after the document is compiled. You can use this |
| 48 |
function to manually load the database anywhere in the document (even before |
| 49 |
the code chunk). This makes it possible to use objects created later in the |
| 50 |
document earlier, e.g. in an inline R expression before the cached code |
| 51 |
chunk, which is normally not possible because \pkg{knitr} compiles the |
| 52 |
document in a linear fashion, and objects created later cannot be used before |
| 53 |
they are created. |
| 54 |
} |
| 55 |
\note{ |
| 56 |
Apparently this function loads the value of the object from the |
| 57 |
\emph{previous} run of the document, which may be problematic when the |
| 58 |
value of the object becomes different the next time the document is |
| 59 |
compiled. Normally you must compile the document twice to make sure the |
| 60 |
cache database is created, and the object can be read from it. Please use |
| 61 |
this function with caution. |
| 62 |
} |
| 63 |
\references{ |
| 64 |
See the example #114 at |
| 65 |
\url{https://github.com/yihui/knitr-examples}. |
| 66 |
} |