Arguments
- expr
(expression) A bare expression that can (optionally) contain
rvars. The expression supports quasiquotation.- dim
(integer vector) One or more integers giving the maximal indices in each dimension to override the dimensions of the
rvarto be created (seedim()). IfNULL(the default),dimis determined by the input. NOTE: This argument controls the dimensions of thervar, not the underlying array, so you cannot change the number of draws using this argument.- ndraws
(positive integer) The number of draws used to construct new random variables if no
rvars are supplied inexpr. IfNULL,getOption("posterior.rvar_ndraws")is used (default 4000). Ifexprcontainsrvars, the number of draws in the providedrvars is used instead of the value of this argument.
Value
An rvar.
Details
This function evaluates expr possibly multiple times, once for each draw of
the rvars it contains, then returns a new rvar representing the output of those
expressions. To identify rvars, rdo() searches the calling environment for any variables
named in expr for which is_rvar() evaluates to TRUE. If expr contains no rvars,
then it will be executed ndraws times and an rvar with that many draws returned.
rdo() is not necessarily fast (in fact in some cases it may be very slow), but
it has the advantage of allowing a nearly arbitrary R expression to be executed against rvars
simply by wrapping it with rdo( ... ). This makes it especially useful as a prototyping
tool. If you create code with rdo() and it is unacceptably slow for your application,
consider rewriting it using math operations directly on rvars (which should be fast),
using rvar_rng(), and/or using operations directly on the arrays that back the rvars
(via draws_of()).
See also
Other rfun:
rfun(),
rvar_rng()