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.9186 dplyr_0.4.1 webshot_0.3.2 #> [4] htmltools_0.3.6 devtools_1.12.0.9000 memoise_1.1.0 #> [7] RColorBrewer_1.1-2 chorddiag_0.1.1 networkD3_0.2.13 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.11 tools_3.2.5 testthat_1.0.2 #> [4] highlight_0.4.7.1 digest_0.6.12 pkgload_0.0.0.9000 #> [7] jsonlite_1.5 evaluate_0.10 tibble_1.3.3 #> [10] rlang_0.1.1.9000 igraph_1.0.1 DBI_0.6-1 #> [13] rstudioapi_0.6 commonmark_1.2 yaml_2.1.14 #> [16] parallel_3.2.5 pkgdown_0.1.0.9000 httr_1.2.1 #> [19] withr_1.0.2 stringr_1.2.0 roxygen2_6.0.1 #> [22] knitr_1.16 xml2_1.1.1 desc_1.1.0 #> [25] htmlwidgets_0.8 rprojroot_1.2 R6_2.2.1 #> [28] pooh_0.3-2 rmarkdown_1.5 callr_1.0.0 #> [31] whisker_0.3-2 purrr_0.2.2.2 magrittr_1.5 #> [34] backports_1.1.0 usethis_0.0.0.9000 assertthat_0.2.0.9000 #> [37] stringi_1.1.5 crayon_1.3.2not_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.9186 dplyr_0.4.1 webshot_0.3.2 #> [4] htmltools_0.3.6 devtools_1.12.0.9000 memoise_1.1.0 #> [7] RColorBrewer_1.1-2 chorddiag_0.1.1 networkD3_0.2.13 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.11 tools_3.2.5 testthat_1.0.2 #> [4] highlight_0.4.7.1 digest_0.6.12 pkgload_0.0.0.9000 #> [7] jsonlite_1.5 evaluate_0.10 tibble_1.3.3 #> [10] rlang_0.1.1.9000 igraph_1.0.1 DBI_0.6-1 #> [13] rstudioapi_0.6 commonmark_1.2 yaml_2.1.14 #> [16] parallel_3.2.5 pkgdown_0.1.0.9000 httr_1.2.1 #> [19] withr_1.0.2 stringr_1.2.0 roxygen2_6.0.1 #> [22] knitr_1.16 xml2_1.1.1 desc_1.1.0 #> [25] htmlwidgets_0.8 rprojroot_1.2 R6_2.2.1 #> [28] pooh_0.3-2 rmarkdown_1.5 callr_1.0.0 #> [31] whisker_0.3-2 purrr_0.2.2.2 magrittr_1.5 #> [34] backports_1.1.0 usethis_0.0.0.9000 assertthat_0.2.0.9000 #> [37] stringi_1.1.5 crayon_1.3.2print(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.9186 dplyr_0.4.1 webshot_0.3.2 #> [4] htmltools_0.3.6 devtools_1.12.0.9000 memoise_1.1.0 #> [7] RColorBrewer_1.1-2 chorddiag_0.1.1 networkD3_0.2.13 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.11 tools_3.2.5 testthat_1.0.2 #> [4] highlight_0.4.7.1 digest_0.6.12 pkgload_0.0.0.9000 #> [7] jsonlite_1.5 evaluate_0.10 tibble_1.3.3 #> [10] rlang_0.1.1.9000 igraph_1.0.1 DBI_0.6-1 #> [13] rstudioapi_0.6 commonmark_1.2 yaml_2.1.14 #> [16] parallel_3.2.5 pkgdown_0.1.0.9000 httr_1.2.1 #> [19] withr_1.0.2 stringr_1.2.0 roxygen2_6.0.1 #> [22] knitr_1.16 xml2_1.1.1 desc_1.1.0 #> [25] htmlwidgets_0.8 rprojroot_1.2 R6_2.2.1 #> [28] pooh_0.3-2 rmarkdown_1.5 callr_1.0.0 #> [31] whisker_0.3-2 purrr_0.2.2.2 magrittr_1.5 #> [34] backports_1.1.0 usethis_0.0.0.9000 assertthat_0.2.0.9000 #> [37] stringi_1.1.5 crayon_1.3.2not_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.9186 dplyr_0.4.1 webshot_0.3.2 #> [4] htmltools_0.3.6 devtools_1.12.0.9000 memoise_1.1.0 #> [7] RColorBrewer_1.1-2 chorddiag_0.1.1 networkD3_0.2.13 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.11 tools_3.2.5 testthat_1.0.2 #> [4] highlight_0.4.7.1 digest_0.6.12 pkgload_0.0.0.9000 #> [7] jsonlite_1.5 evaluate_0.10 tibble_1.3.3 #> [10] rlang_0.1.1.9000 igraph_1.0.1 DBI_0.6-1 #> [13] rstudioapi_0.6 commonmark_1.2 yaml_2.1.14 #> [16] parallel_3.2.5 pkgdown_0.1.0.9000 httr_1.2.1 #> [19] withr_1.0.2 stringr_1.2.0 roxygen2_6.0.1 #> [22] knitr_1.16 xml2_1.1.1 desc_1.1.0 #> [25] htmlwidgets_0.8 rprojroot_1.2 R6_2.2.1 #> [28] pooh_0.3-2 rmarkdown_1.5 callr_1.0.0 #> [31] whisker_0.3-2 purrr_0.2.2.2 magrittr_1.5 #> [34] backports_1.1.0 usethis_0.0.0.9000 assertthat_0.2.0.9000 #> [37] stringi_1.1.5 crayon_1.3.2## 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()) }#> [2017-06-21T21:58:32 UTC] 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()) }#> [2017-06-21T21:58:32 UTC] Defining 'foos/foobaz' ... OK## EOF ## Not run: make()