Temporarily unload and detach packages, and optionally use a specific packages library for the module.
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. |
The result of the evaluation of the code
argument.
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.
This is an experimental feature subject to changes.
withr
for examples of 'with_' methods,
getOption
, library
, options
, and
search
.
print(sessionInfo())#> R version 3.2.5 (2016-04-14) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: Red Hat Enterprise Linux #> #> locale: #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_DK.UTF-8 LC_COLLATE=en_US.UTF-8 #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] modulr_0.1.7.9209 memoise_1.1.0 testthat_2.0.0.9000 #> #> loaded via a namespace (and not attached): #> [1] clisymbols_1.2.0 remotes_2.0.1.9000 purrr_0.2.4 #> [4] rcmdcheck_1.3.0 usethis_1.4.0.9000 htmltools_0.3.6 #> [7] yaml_2.1.16 base64enc_0.1-3 rlang_0.3.0.1 #> [10] pkgbuild_1.0.2.9000 pkgdown_0.1.0.9000 pillar_1.1.0 #> [13] glue_1.3.0 withr_2.1.2 xopen_1.0.0 #> [16] sessioninfo_1.1.0.9001 networkD3_0.2.13 stringr_1.3.1 #> [19] commonmark_1.2 devtools_2.0.0.9000 htmlwidgets_0.8 #> [22] evaluate_0.10.1 knitr_1.19 callr_3.0.0.9001 #> [25] highlight_0.4.7.1 ps_1.2.0 Rcpp_0.12.19 #> [28] backports_1.1.2 desc_1.2.0 pkgload_1.0.1.9000 #> [31] debugme_1.1.0 jsonlite_1.5 fs_1.2.6 #> [34] digest_0.6.18 stringi_1.2.4 processx_3.2.0 #> [37] rprojroot_1.3-2 pooh_0.3-2 cli_1.0.1.9000 #> [40] tools_3.2.5 magrittr_1.5 tibble_1.4.2 #> [43] crayon_1.3.4 whisker_0.3-2 xml2_1.2.0.9000 #> [46] prettyunits_1.0.2 assertthat_0.2.0 rmarkdown_1.8 #> [49] roxygen2_6.1.0 httr_1.3.1 rstudioapi_0.8.0.9000 #> [52] R6_2.3.0 igraph_1.0.1not_run({ with_no_packages({ message("Look mum, no packages!") print(sessionInfo()) }) }) print(sessionInfo())#> R version 3.2.5 (2016-04-14) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: Red Hat Enterprise Linux #> #> locale: #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_DK.UTF-8 LC_COLLATE=en_US.UTF-8 #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] modulr_0.1.7.9209 memoise_1.1.0 testthat_2.0.0.9000 #> #> loaded via a namespace (and not attached): #> [1] clisymbols_1.2.0 remotes_2.0.1.9000 purrr_0.2.4 #> [4] rcmdcheck_1.3.0 usethis_1.4.0.9000 htmltools_0.3.6 #> [7] yaml_2.1.16 base64enc_0.1-3 rlang_0.3.0.1 #> [10] pkgbuild_1.0.2.9000 pkgdown_0.1.0.9000 pillar_1.1.0 #> [13] glue_1.3.0 withr_2.1.2 xopen_1.0.0 #> [16] sessioninfo_1.1.0.9001 networkD3_0.2.13 stringr_1.3.1 #> [19] commonmark_1.2 devtools_2.0.0.9000 htmlwidgets_0.8 #> [22] evaluate_0.10.1 knitr_1.19 callr_3.0.0.9001 #> [25] highlight_0.4.7.1 ps_1.2.0 Rcpp_0.12.19 #> [28] backports_1.1.2 desc_1.2.0 pkgload_1.0.1.9000 #> [31] debugme_1.1.0 jsonlite_1.5 fs_1.2.6 #> [34] digest_0.6.18 stringi_1.2.4 processx_3.2.0 #> [37] rprojroot_1.3-2 pooh_0.3-2 cli_1.0.1.9000 #> [40] tools_3.2.5 magrittr_1.5 tibble_1.4.2 #> [43] crayon_1.3.4 whisker_0.3-2 xml2_1.2.0.9000 #> [46] prettyunits_1.0.2 assertthat_0.2.0 rmarkdown_1.8 #> [49] roxygen2_6.1.0 httr_1.3.1 rstudioapi_0.8.0.9000 #> [52] R6_2.3.0 igraph_1.0.1print(sessionInfo())#> R version 3.2.5 (2016-04-14) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: Red Hat Enterprise Linux #> #> locale: #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_DK.UTF-8 LC_COLLATE=en_US.UTF-8 #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] modulr_0.1.7.9209 memoise_1.1.0 testthat_2.0.0.9000 #> #> loaded via a namespace (and not attached): #> [1] clisymbols_1.2.0 remotes_2.0.1.9000 purrr_0.2.4 #> [4] rcmdcheck_1.3.0 usethis_1.4.0.9000 htmltools_0.3.6 #> [7] yaml_2.1.16 base64enc_0.1-3 rlang_0.3.0.1 #> [10] pkgbuild_1.0.2.9000 pkgdown_0.1.0.9000 pillar_1.1.0 #> [13] glue_1.3.0 withr_2.1.2 xopen_1.0.0 #> [16] sessioninfo_1.1.0.9001 networkD3_0.2.13 stringr_1.3.1 #> [19] commonmark_1.2 devtools_2.0.0.9000 htmlwidgets_0.8 #> [22] evaluate_0.10.1 knitr_1.19 callr_3.0.0.9001 #> [25] highlight_0.4.7.1 ps_1.2.0 Rcpp_0.12.19 #> [28] backports_1.1.2 desc_1.2.0 pkgload_1.0.1.9000 #> [31] debugme_1.1.0 jsonlite_1.5 fs_1.2.6 #> [34] digest_0.6.18 stringi_1.2.4 processx_3.2.0 #> [37] rprojroot_1.3-2 pooh_0.3-2 cli_1.0.1.9000 #> [40] tools_3.2.5 magrittr_1.5 tibble_1.4.2 #> [43] crayon_1.3.4 whisker_0.3-2 xml2_1.2.0.9000 #> [46] prettyunits_1.0.2 assertthat_0.2.0 rmarkdown_1.8 #> [49] roxygen2_6.1.0 httr_1.3.1 rstudioapi_0.8.0.9000 #> [52] R6_2.3.0 igraph_1.0.1not_run({ with_packages("~/my_packages", { if (!"pooh" %in% rownames(utils::installed.packages())) utils::install.packages("pooh") library(pooh) print(sessionInfo()) }) }) print(sessionInfo())#> R version 3.2.5 (2016-04-14) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: Red Hat Enterprise Linux #> #> locale: #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C #> [3] LC_TIME=en_DK.UTF-8 LC_COLLATE=en_US.UTF-8 #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C #> [9] LC_ADDRESS=C LC_TELEPHONE=C #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] modulr_0.1.7.9209 memoise_1.1.0 testthat_2.0.0.9000 #> #> loaded via a namespace (and not attached): #> [1] clisymbols_1.2.0 remotes_2.0.1.9000 purrr_0.2.4 #> [4] rcmdcheck_1.3.0 usethis_1.4.0.9000 htmltools_0.3.6 #> [7] yaml_2.1.16 base64enc_0.1-3 rlang_0.3.0.1 #> [10] pkgbuild_1.0.2.9000 pkgdown_0.1.0.9000 pillar_1.1.0 #> [13] glue_1.3.0 withr_2.1.2 xopen_1.0.0 #> [16] sessioninfo_1.1.0.9001 networkD3_0.2.13 stringr_1.3.1 #> [19] commonmark_1.2 devtools_2.0.0.9000 htmlwidgets_0.8 #> [22] evaluate_0.10.1 knitr_1.19 callr_3.0.0.9001 #> [25] highlight_0.4.7.1 ps_1.2.0 Rcpp_0.12.19 #> [28] backports_1.1.2 desc_1.2.0 pkgload_1.0.1.9000 #> [31] debugme_1.1.0 jsonlite_1.5 fs_1.2.6 #> [34] digest_0.6.18 stringi_1.2.4 processx_3.2.0 #> [37] rprojroot_1.3-2 pooh_0.3-2 cli_1.0.1.9000 #> [40] tools_3.2.5 magrittr_1.5 tibble_1.4.2 #> [43] crayon_1.3.4 whisker_0.3-2 xml2_1.2.0.9000 #> [46] prettyunits_1.0.2 assertthat_0.2.0 rmarkdown_1.8 #> [49] roxygen2_6.1.0 httr_1.3.1 rstudioapi_0.8.0.9000 #> [52] R6_2.3.0 igraph_1.0.1## 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()) }#> [2018-12-02T17:14:13 CET] Defining 'foos/foobar' ... OK## 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()) }#> [2018-12-02T17:14:13 CET] Defining 'foos/foobaz' ... OK## EOF ## Not run: make()