| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/command.R |
| 3 |
\name{Rscript_call} |
| 4 |
\alias{Rscript_call} |
| 5 |
\title{Call a function in a new R session via \code{Rscript()}} |
| 6 |
\usage{ |
| 7 |
Rscript_call( |
| 8 |
fun, |
| 9 |
args = list(), |
| 10 |
options = NULL, |
| 11 |
..., |
| 12 |
wait = TRUE, |
| 13 |
fail = sprintf("Failed to run '\%s' in a new R session", deparse(substitute(fun))[1]) |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{fun}{A function, or a character string that can be parsed and evaluated |
| 18 |
to a function.} |
| 19 |
|
| 20 |
\item{args}{A list of argument values.} |
| 21 |
|
| 22 |
\item{options}{A character vector of options to passed to \code{\link[=Rscript]{Rscript()}}, e.g., |
| 23 |
\code{"--vanilla"}.} |
| 24 |
|
| 25 |
\item{..., wait}{Arguments to be passed to \code{\link[=system2]{system2()}}.} |
| 26 |
|
| 27 |
\item{fail}{The desired error message when an error occurred in calling the |
| 28 |
function. If the actual error message during running the function is |
| 29 |
available, it will be appended to this message.} |
| 30 |
} |
| 31 |
\value{ |
| 32 |
If \code{wait = TRUE}, the returned value of the function in the new R |
| 33 |
session. If \code{wait = FALSE}, three file paths will be returned: the first |
| 34 |
one stores \code{fun} and \code{args} (as a list), the second one is supposed to |
| 35 |
store the returned value of the function, and the third one stores the |
| 36 |
possible error message. |
| 37 |
} |
| 38 |
\description{ |
| 39 |
Save the argument values of a function in a temporary RDS file, open a new R |
| 40 |
session via \code{\link[=Rscript]{Rscript()}}, read the argument values, call the function, and |
| 41 |
read the returned value back to the current R session. |
| 42 |
} |
| 43 |
\examples{ |
| 44 |
factorial(10) |
| 45 |
# should return the same value |
| 46 |
xfun::Rscript_call("factorial", list(10)) |
| 47 |
|
| 48 |
# the first argument can be either a character string or a function |
| 49 |
xfun::Rscript_call(factorial, list(10)) |
| 50 |
|
| 51 |
# Run Rscript starting a vanilla R session |
| 52 |
xfun::Rscript_call(factorial, list(10), options = c("--vanilla")) |
| 53 |
} |