View source: R/execute_with_packages.R
lib.execute_using_packagelist | R Documentation |
This function can be used to perform R operations with a configured set of packages to load in a separate R process.
The package callr
is required to use this functionality.
It will start a new process, then load the provided packages and execute your function.
The callr
package may be provided via the R_MV_library or your standard library,
in which case it must be in a library where .libPaths
is pointing to.
lib.execute_using_packagelist( packages_to_load = c(), func_handle, ..., .lib_location = lib.location(), .pick_last = FALSE, .also_load_from_temp_lib = FALSE, .wait_for_response = TRUE, .run_quietly = FALSE, .callr_arguments = list() )
packages_to_load |
An array indicating which packages must be loaded
like " |
func_handle |
A function object or the function name as a character string. |
... |
Provide all the remaining arguments which will be arguments for the function handle. Note that every argument must be named and must match an argument in your func_handle. |
.lib_location |
The location of the version controlled library. Defaults to lib.location(), which is the directory provided by the environment variable. |
.pick_last |
Passed to |
.also_load_from_temp_lib |
Passed to |
.wait_for_response |
If false, it will fire and forget and return immediately
using |
.run_quietly |
Controls the 'show' parameter of |
.callr_arguments |
List specifying additional arguments for |
The additional arguments to callr: .callr_arguments
, can for example be used
to keep a log of a detached process. By including the following
.callr_arguments
for example:
lib.execute_using_packagelist( ..., .callr_arguments = list(stdout = paste0('./execution_', gsub('\s|-|:', '_', format(Sys.time())), '.log'), stderr = "2>&1") )
See the example below for a complete example.
When you do this, it somehow swallows the first character of every stderr
that is directly returned (also from message
calls) when
run_quietly = FALSE
, but the log file seems intact.
Will return the outcome of your func_handle
.
If you would like to log the outcomes, provide the .callr_arguments:
lib.execute_using_packagelist( packages_to_load = c(package.a = '0.1.0'), func_handle = function() {an_important_value(); package_a1(5, 10)}, .wait_for_response = TRUE, .callr_arguments = list(stdout = paste0('./execution_', gsub('\s|-|:', '_', format(Sys.time())), '.log'), stderr = "2>&1"), .run_quietly = TRUE )
Another more simple example:
lib.execute_using_packagelist( packages_to_load = c(dplyr = ''), func_handle = function() {mtcars} )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.