use_package_cache | R Documentation |
These functions explicitly gives sandpaper permission to use renv to create a package cache for this and future lessons. There are two states that you can use:
use_package_cache()
: Gives explicit permission to set up and use the
package cache with your lesson.
no_package_cache()
: Temporarily suspends permission to use the package
cache with your lesson, regardless if it was previously given.
Once you have a package cache defined, you can use changes in the lockfile to trigger rebuilds of the lesson. To do this, you can use:
package_cache_trigger(TRUE)
The above function is best used in conjunction with update_cache()
use_package_cache(prompt = interactive(), quiet = !prompt)
no_package_cache()
package_cache_trigger(rebuild = NULL)
prompt |
if |
quiet |
if |
rebuild |
The new value of the |
By default, sandpaper will happily build your lesson using the packages available in your default R library, but this can be undesirable for a couple of reasons:
You may have a different version of a lesson package that is used on the lesson website, which may result in strange errors, warnings, or incorrect output.
You might be very cautious about updating any components of your current R infrastructure because your work depends on you having the correct package versions installed.
To alleviate these concerns, sandpaper uses the renv package to generate a lesson-specific library that has package versions pinned until the lesson authors choose to update them. This is designed to be minimally-invasive, using the packages you already have and downloading from external repositories only when necessary.
If you have used renv in the past, then there is no need to give consent to use the cache.
To turn off the feature you can use no_package_cache()
. sandpaper
will respect this option when building your lesson and will use your global
library instead.
You can set options(sandpaper.use_renv = FALSE)
before loading {sandpaper}
.
nothing. this is used for its side-effect
the value of getOption("sandpaper.package_cache_trigger")
or
FALSE
, if it is unset.
manage_deps()
and update_cache()
for managing the requirements
inside the package cache.
if (!getOption("sandpaper.use_renv") && interactive()) {
# The first time you set up `{renv}`, you will need permission
use_package_cache(prompt = TRUE)
# The package cache trigger is FALSE, by default
default <- package_cache_trigger()
# You can set this to `TRUE` when you update packages with `update_cache()`
package_cache_trigger(TRUE)
# set the trigger back to its former state
package_cache_trigger(default)
}
if (getOption("sandpaper.use_renv") && interactive()) {
# If you have previously used `{renv}`, permission is implied
use_package_cache(prompt = TRUE)
# You can temporarily turn this off
no_package_cache()
getOption("sandpaper.use_renv") # should be FALSE
use_package_cache(prompt = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.