Description Usage Arguments Details Value Examples
The .
function allows writing an R function call in a Lisp-like
prefix format, rather than the Algol-like infix format that R usually
uses. prefix
and infix
convert R code between infix and
prefix.
1 2 3 4 5 |
expr |
A prefix- or infix-formatted expression to convert. Code between "R(" and ")" will not be converted. |
f |
The function that |
... |
Further arguments to the function f. |
When evaluated, a call to .
doesn't actually execute the function
that's been expressed in prefix style, just generates the corresponding
infix call. It's intended as a notational aid, so that entire scripts
can be written in the prefix form.
A call to prefix()
does not evaluate the passed
or the generated expressions, partly for efficiency reasons; infix()
,
though it still does not evaluate the generated expression, does do
partial evaluation of the passed expression: each call to .
is
evaluated to the corresponding infix call.
infix
and prefix
are not quite inverses of each other, because
infix
understands certain pieces of infix syntactic sugar. Examples
include the ".q" and ".b" quoting abbreviations, and the lambda lists passed
to lambda
, macro
and defmacro
.
prefix
and infix
return the input expression
converted to prefix or infix.
.
returns an unevaluated call to f with ...
arguments
carried through.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | prefix(expression(x <- runif(10), y <- runif(10), cor(x, y)))
prefix(expression(with(datasets::iris, sum(Sepal.Length^2 + Petal.Width))))
infix(expression(.(`<-`, x, .(runif, 10)), .(`<-`, y, .(runif, 10)),
.(cor, x, y)))
infix(expression(.(with, .(`::`, datasets, iris),
.(sum, .(`+`, .(`^`, Sepal.Length, 2),
Petal.Width)))))
.(`+`, 1, 2)
.(sum, .(runif, 10), .(runif, 10))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.