Description Usage Arguments Details Value Warning See Also Examples
Temporarily unload and detach packages, and optionally use a specific packages library for the module.
1 2 3 4 5 6 7 8 9 | with_no_packages(code, ignore = NULL)
without_packages(code, ignore = NULL)
with_packages(lib_path, code, ...)
with_module_packages(code, ...)
with_namespace_packages(namespace, code, ...)
|
code |
Any object. Code to execute in the temporary environment. |
ignore |
A vector of character strings. Packages (in addition to base packages) to ignore in the process. |
lib_path |
A string (character vector of length one) containing the path of the packages library. |
... |
Further arguments to be passed to |
namespace |
A string (character vector of length one) containing the namespace of the module to be used as path for the packages library. |
Packages are temporarily unloaded and detached from the search path. When
restored, the ordering of the packages on the search path is preserved. Base
packages and packages passed to the ignore
parameter are ignored in
the process. By default, the vector of names of ignored packages is taken
from the modulr.ignore_packages
R option.
with_packages
uses the library given by lib_path
.
with_module_packages
uses a dedicated library for the module, using
the module name as path.
with_namespace_packages
uses a shared library for all the modules
under the given namespace
parameter.
The result of the evaluation of the code
argument.
This is an experimental feature subject to changes.
withr
for examples of 'with_' methods,
getOption
, library
, options
, and
search
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | print(sessionInfo())
## Not run:
with_no_packages({
message("Look mum, no packages!")
print(sessionInfo())
})
## End(Not run)
print(sessionInfo())
print(sessionInfo())
## Not run:
with_packages("~/my_packages", {
if (!"pooh" %in% rownames(utils::installed.packages()))
utils::install.packages("pooh")
library(pooh)
print(sessionInfo())
})
## End(Not run)
print(sessionInfo())
## In file "foos/foobar.R" # Exclude Linting
"foos/foobar" %provides% {
print(sessionInfo())
with_module_packages({
if (!"devtools" %in% rownames(utils::installed.packages()))
utils::install.packages("devtools")
library(devtools)
if (!"pooh" %in% rownames(utils::installed.packages()))
devtools::install_version("pooh", "0.2")
library(pooh)
print(sessionInfo())
})
print(sessionInfo())
}
## EOF
## Not run: make()
## In file "foos/foobaz.R" # Exclude Linting
"foos/foobaz" %provides% {
print(sessionInfo())
with_namespace_packages("foos", {
if (!"devtools" %in% rownames(utils::installed.packages()))
utils::install.packages("devtools")
library(devtools)
if (!"pooh" %in% rownames(utils::installed.packages()))
devtools::install_version("pooh", "0.3")
library(pooh)
print(sessionInfo())
})
print(sessionInfo())
}
## EOF
## Not run: make()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.