rcmd {callr} | R Documentation |
Run an R CMD
command
Description
Run an R CMD
command form within R. This will usually start
another R process, from a shell script.
Usage
rcmd(
cmd,
cmdargs = character(),
libpath = .libPaths(),
repos = default_repos(),
stdout = NULL,
stderr = NULL,
poll_connection = TRUE,
echo = FALSE,
show = FALSE,
callback = NULL,
block_callback = NULL,
spinner = show && interactive(),
system_profile = FALSE,
user_profile = "project",
env = rcmd_safe_env(),
timeout = Inf,
wd = ".",
fail_on_status = FALSE,
...
)
rcmd_safe(
cmd,
cmdargs = character(),
libpath = .libPaths(),
repos = default_repos(),
stdout = NULL,
stderr = NULL,
poll_connection = TRUE,
echo = FALSE,
show = FALSE,
callback = NULL,
block_callback = NULL,
spinner = show && interactive(),
system_profile = FALSE,
user_profile = "project",
env = rcmd_safe_env(),
timeout = Inf,
wd = ".",
fail_on_status = FALSE,
...
)
Arguments
cmd |
Command to run. See |
cmdargs |
Command line arguments. |
libpath |
The library path. |
repos |
The |
stdout |
Optionally a file name to send the standard output to. |
stderr |
Optionally a file name to send the standard error to.
It may be the same as |
poll_connection |
Whether to have a control connection to the process. This is used to transmit messages from the subprocess to the parent. |
echo |
Whether to echo the complete command run by |
show |
Logical, whether to show the standard output on the screen
while the child process is running. Note that this is independent
of the |
callback |
A function to call for each line of the standard
output and standard error from the child process. It works together
with the |
block_callback |
A function to call for each block of the standard output and standard error. This callback is not line oriented, i.e. multiple lines or half a line can be passed to the callback. |
spinner |
Whether to show a calming spinner on the screen while
the child R session is running. By default it is shown if
|
system_profile |
Whether to use the system profile file. |
user_profile |
Whether to use the user's profile file.
If this is |
env |
Environment variables to set for the child process. |
timeout |
Timeout for the function call to finish. It can be a
base::difftime object, or a real number, meaning seconds.
If the process does not finish before the timeout period expires,
then a |
wd |
Working directory to use for running the command. Defaults to the current working directory. |
fail_on_status |
Whether to throw an R error if the command returns with a non-zero status code. By default no error is thrown. |
... |
Extra arguments are passed to |
Details
Starting from callr
2.0.0, rcmd()
has safer defaults, the same as
the rcmd_safe()
default values. Use rcmd_copycat()
for the old
defaults.
Value
A list with the command line $command
),
standard output ($stdout
), standard error (stderr
),
exit status ($status
) of the external R CMD
command, and
whether a timeout was reached ($timeout
).
Security considerations
callr
makes a copy of the user's .Renviron
file and potentially of
the local or user .Rprofile
, in the session temporary
directory. Avoid storing sensitive information such as passwords, in
your environment file or your profile, otherwise this information will
get scattered in various files, at least temporarily, until the
subprocess finishes. You can use the keyring package to avoid passwords
in plain files.
See Also
Other R CMD commands:
rcmd_bg()
,
rcmd_copycat()
Examples
rcmd("config", "CC")