with_no_packages: With (...) Packages.

Description Usage Arguments Details Value Warning See Also Examples

View source: R/pkgs.R

Description

Temporarily unload and detach packages, and optionally use a specific packages library for the module.

Usage

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, ...)

Arguments

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 with_no_packages.

namespace

A string (character vector of length one) containing the namespace of the module to be used as path for the packages library.

Details

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.

Value

The result of the evaluation of the code argument.

Warning

This is an experimental feature subject to changes.

See Also

withr for examples of 'with_' methods, getOption, library, options, and search.

Examples

 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()

openscienceunil/modulr documentation built on May 3, 2019, 5:49 p.m.