knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The renv::use()
function can make it easier to define stand-alone R scripts
that include their R package requirements directly in the script itself.
For example:
# write down the set of packages required by this script renv::use( "digest", # use the latest-available version of digest "rlang@0.3.4" # use an older release of rlang (installed from archive) ) # use the requested packages digest::digest(list(answer = 42))
Running a script with these contents will:
Automatically download the requested packages (the latest release of
digest
, alongside rlang 0.3.4
),
Install the requested packages (plus their recursive package dependencies) to a temporary library path,
Activate that library path, so that it's used subsequently in the script.
renv::use()
can hence be a useful way of sharing standalone R scripts with
a set of specific package requirements. Running these scripts will ensure the
requested packages are automatically downloaded and installed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.