Convenience wrappers for exec_wait and exec_internal that shell out to
R itself: R.home("bin/R").
command line arguments for R
if and where to direct child process STDOUT. Must be one of
TRUE, FALSE, filename, connection object or callback function. See section
on Output Streams below for details.
if and where to direct child process STDERR. Must be one of
TRUE, FALSE, filename, connection object or callback function. See section
on Output Streams below for details.
a file to send to stdin, usually an R script (see examples).
automatically raise an error if the exit status is non-zero.
This is a simple but robust way to invoke R commands in a separate process. Use the callr package if you need more sophisticated control over (multiple) R process jobs.
Other sys:
exec
# Hello world
r_wait("--version")
#> R version 4.5.1 (2025-06-13) -- "Great Square Root"
#> Copyright (C) 2025 The R Foundation for Statistical Computing
#> Platform: x86_64-pc-linux-gnu
#>
#> R is free software and comes with ABSOLUTELY NO WARRANTY.
#> You are welcome to redistribute it under the terms of the
#> GNU General Public License versions 2 or 3.
#> For more information about these matters see
#> https://www.gnu.org/licenses/.
#>
#> [1] 0
# Run some code
r_wait(c('--vanilla', '-q', '-e', 'sessionInfo()'))
#> > sessionInfo()
#> R version 4.5.1 (2025-06-13)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.3 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
#> [4] LC_COLLATE=C LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
#> [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_4.5.1
#> >
#> [1] 0
# Run a script via stdin
tmp <- tempfile()
writeLines(c("x <- rnorm(100)", "mean(x)"), con = tmp)
r_wait(std_in = tmp)
#>
#> R version 4.5.1 (2025-06-13) -- "Great Square Root"
#> Copyright (C) 2025 The R Foundation for Statistical Computing
#> Platform: x86_64-pc-linux-gnu
#>
#> R is free software and comes with ABSOLUTELY NO WARRANTY.
#> You are welcome to redistribute it under certain conditions.
#> Type 'license()' or 'licence()' for distribution details.
#>
#> R is a collaborative project with many contributors.
#> Type 'contributors()' for more information and
#> 'citation()' on how to cite R or R packages in publications.
#>
#> Type 'demo()' for some demos, 'help()' for on-line help, or
#> 'help.start()' for an HTML browser interface to help.
#> Type 'q()' to quit R.
#>
#> > x <- rnorm(100)
#> > mean(x)
#> [1] -0.13552
#> >
#> [1] 0