1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/command.R
\name{Rscript_call}
\alias{Rscript_call}
\title{Call a function in a new R session via \code{Rscript()}}
\usage{
Rscript_call(
fun,
args = list(),
...,
wait = TRUE,
fail = sprintf("Failed to run '\%s' in a new R session.",
deparse(substitute(fun))[1])
)
}
\arguments{
\item{fun}{A function, or a character string that can be parsed and evaluated
to a function.}
\item{args}{A list of argument values.}
\item{..., wait}{Arguments to be passed to \code{\link{system2}()}.}
\item{fail}{The desired error message when an error occurred in calling the
function.}
}
\value{
The returned value of the function in the new R session.
}
\description{
Save the argument values of a function in a temporary RDS file, open a new R
session via \code{\link{Rscript}()}, read the argument values, call the
function, and read the returned value back to the current R session.
}
\examples{
factorial(10)
# should return the same value
xfun::Rscript_call("factorial", list(10))
# the first argument can be either a character string or a function
xfun::Rscript_call(factorial, list(10))
}
|