Run expressions in environments
runInEnv.Rd
Execute R expressions in multiple environments.
Usage
runInEnv(
expr,
envName = envList(),
parallel = FALSE,
ncores = parallel::detectCores() - 1
)
Arguments
- expr
An R expression or a `character()` (deparsed R expression) that will be evaluated.
- envName
A `character()` specifying the environment(s) name(s).
- parallel
A `logical(1)` indicating whether to run expressions in parallel. Default is `FALSE`.
- ncores
An `integer(1)` specifying the number of cores to use for parallel execution. Default is `parallel::detectCores() - 1`.
Value
The result of the evaluated expression when length(envName) == 1.
A list of results for each environment when length(envName) > 1.
Examples
envCreate("my_env", packages = c("jsonlite@1.9.1"))
#> # Downloading packages -------------------------------------------------------
#> - Downloading jsonlite from Repository ... OK [1 Mb in 0.46s]
#> Successfully downloaded 1 package in 1.1 seconds.
#>
#> The following package(s) will be installed:
#> - jsonlite [1.9.1]
#> These packages will be installed into "~/work/VerR/VerR/docs/reference/.envs/my_env/renv/library/linux-ubuntu-noble/R-4.5/x86_64-pc-linux-gnu".
#>
#> # Installing packages --------------------------------------------------------
#> - Installing jsonlite ... OK [installed binary and cached in 0.23s]
#> Successfully installed 1 package in 0.27 seconds.
#> Installed packages in environment: /home/runner/work/VerR/VerR/docs/reference/.envs/my_env
#> - The project is out-of-sync -- use `renv::status()` for details.
#> The following package(s) will be updated in the lockfile:
#>
#> # RSPM -----------------------------------------------------------------------
#> - jsonlite [2.0.0 -> 1.9.1]
#>
#> - Lockfile written to "~/work/VerR/VerR/docs/reference/.envs/my_env/renv.lock".
#> Updated lockfile in environment: .envs/my_env
runInEnv(packageVersion("jsonlite"), "my_env")
#> Warning: path[1]="/tmp/RtmpMZqma5/result.rds": No such file or directory
#> Warning: path[1]="/tmp/RtmpMZqma5/result.rds": No such file or directory
#> [1] ‘1.9.1’
runInEnv(packageVersion("jsonlite"))
#> [1] ‘1.9.1’
envDelete(force = TRUE)
#> Cleared environment: my_env
#> Removed '.envs' directory as no environments are left.