View source: R/utils-rstudio.R
rs_exec | R Documentation |
Utilizes 'RStudio' job scheduler if correct environment is
detected, otherwise call system command via Rscript
rs_exec(
expr,
name = "Untitled",
quoted = FALSE,
rs = TRUE,
as_promise = FALSE,
wait = FALSE,
packages = NULL,
focus_on_console = FALSE,
...,
nested_ok = FALSE
)
expr |
R expression |
name |
used by 'RStudio' as name of the job |
quoted |
is |
rs |
whether to use 'RStudio' by default |
as_promise |
whether to return as a |
wait |
whether to wait for the result. |
packages |
packages to load in the sub-sessions |
focus_on_console |
whether to return back to console after creating
jobs; useful when users want to focus on writing code; default is false.
This feature works with 'RStudio' ( |
... |
internally used |
nested_ok |
whether nested |
'RStudio' provides interfaces jobRunScript
to
schedule background jobs. However, this
functionality only applies using 'RStudio' IDE. When launching R from
other places such as terminals, the job scheduler usually result in
errors. In this case, the alternative is to call system command via
Rscript
The expression expr
will run a clean environment. Therefore R objects
created outside of the context will be inaccessible from within the child
environment, and packages except for base packages will not be loaded.
There is a small difference when running within and without 'RStudio'.
When running via Rscript
, the environment will run under
vanilla
argument, which means no load, no start-up code. If you
have start-up code stored at ~/.Rprofile
, the start-up code will be
ignored. When running within 'RStudio', the start-up code will be executed.
As of rstudioapi
version 0.11, there is no 'vanilla' option. This
feature is subject to change in the future.
If wait=TRUE
, returns evaluation results of expr
,
otherwise a function that can track the state of job.
if(interactive()){
h <- rs_exec(
{
Sys.sleep(2)
print(Sys.getpid())
},
wait = FALSE, name = 'Test',
focus_on_console = TRUE
)
code <- h()
print(code)
# wait 3 seconds
Sys.sleep(3)
code <- h()
attributes(code)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.