Added more load_cache() arguments to avoid clobbering global environment #1905
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bioconductor's OSCA book uses
load_cache()
to pull knitr-cached content from already-compiled chapters to enable their re-use when compiling later chapters. By and large, this works pretty well butload_cache()
has the unfortunate side effect of loading everything in the labelled chunk into the global environment, not just theobject
I asked for. To illustrate, let's say we have a very simple Rmarkdown document:When I compile it with
rmarkdown::render
, restart the R session and load the chunk, I get:This can be annoying when an object in my current environment (in an interactive R session, or during the course of compiling an Rmarkdon document) is silently and unintentionally overwritten. The solution presented in this PR adds a few arguments to
load_cache()
that give the caller a bit more control. The first is anenvir=
option that defines a workspace for cache loading, other than the default environment fromknit_global()
.The second argument (
dir=
) is just a quality-of-life change so thatload_cache()
can be more easily called outside of a knitr context (e.g., in an interactive session), specifically by ignoring the (lack of) anoutput.dir
setting.In both cases, the defaults should preserve the current behavior of the function.
Session information