Run a function (job) in another session
Arguments
- fun
function to evaluate
- fun_args
list of function arguments
- packages
list of packages to load
- workdir
working directory; default is temporary path
- method
job type; choices are
'rs_job'
(only used in'RStudio'
environment),'mirai'
(when package'mirai'
is installed), and'callr'
.- name
name of the job
- job_id
job identification number
- timeout
timeout in seconds before the resolve ends; jobs that are still running are subject to
unresolved
policy- auto_remove
whether to automatically remove the job if resolved; default it true
- unresolved
what to do if the job is still running after timing-out; default is
'warning'
and returnNULL
, other choices are'error'
or'silent'
Value
For start_job
, a string of job identification number;
check_job
returns the job status; resolve_job
returns
the function result.
Examples
if (FALSE) { # \dontrun{
# Basic use
job_id <- start_job(function() {
Sys.sleep(1)
Sys.getpid()
})
check_job(job_id)
result <- resolve_job(job_id)
# As promise
library(promises)
as.promise(
start_job(function() {
Sys.sleep(1)
Sys.getpid()
})
) %...>%
print()
} # }