Run an R CMD command form within R. This will usually start another R process, from a shell script.
rcmd(cmd, cmdargs = character(), libpath = .libPaths(),
repos = c(getOption("repos"), c(CRAN = "https://cloud.r-project.org")),
stdout = NULL, stderr = NULL, echo = FALSE, show = FALSE,
callback = NULL, block_callback = NULL, spinner = show && interactive(),
system_profile = FALSE, user_profile = FALSE, env = rcmd_safe_env(),
timeout = Inf, wd = ".", fail_on_status = FALSE)rcmd_safe(cmd, cmdargs = character(), libpath = .libPaths(),
repos = c(getOption("repos"), c(CRAN = "https://cloud.r-project.org")),
stdout = NULL, stderr = NULL, echo = FALSE, show = FALSE,
callback = NULL, block_callback = NULL, spinner = show && interactive(),
system_profile = FALSE, user_profile = FALSE, env = rcmd_safe_env(),
timeout = Inf, wd = ".", fail_on_status = FALSE)
Command to run. See R --help
from the command
line for the various commands. In the current version of R (3.2.4)
these are: BATCH, COMPILE, SHLIB, INSTALL, REMOVE, build, check,
LINK, Rprof, Rdconv, Rd2pdf, Rd2txt, Stangle, Sweave, Rdiff, config,
javareconf, rtags.
Command line arguments.
The library path.
The repos option. If NULL
, then no
repos option is set. This options is only used if
user_profile
or system_profile
is set FALSE
,
as it is set using the system or the user profile.
Optionally a file name to send the standard output to.
Optionally a file name to send the standard error to.
Whether to echo the complete command run by rcmd
.
Logical, whether to show the standard output on the screen
while the child process is running. Note that this is independent
of the stdout
and stderr
arguments. The standard
error is not shown currently.
A function to call for each line of the standard
output and standard error from the child process. It works together
with the show
option; i.e. if show = TRUE
, and a
callback is provided, then the output is shown of the screen, and the
callback is also called.
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.
Whether to show a calming spinner on the screen while
the child R session is running. By default it is shown if
show = TRUE
and the R session is interactive.
Whether to use the system profile file.
Whether to use the user's profile file.
Environment variables to set for the child process.
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 system_command_timeout_error
error is thrown. Inf
means no timeout.
Working directory to use for running the command. Defaults to the current working directory.
Whether to throw an R error if the command returns with a non-zero status code. By default no error is thrown.
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
).
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.
Other R CMD commands: rcmd_bg
,
rcmd_copycat
# NOT RUN {
rcmd("config", "CC")
# }
Run the code above in your browser using DataLab