Description Usage Arguments Value Note Limitations Examples
schemeR() allows embedding Scheme-like code written in prefix
format, with the option of using various Lisp operators and features
including macros, into R code. The code in question is still syntactically
valid R, but has to be converted from prefix
to
infix
to be readily executable. Passing it to schemeR does the
conversion and evaluates the resulting 'traditional' R code, with some control
over the environment in which the evaluation is done.
1 |
expr |
An expression, usually a block expression between "{" and "}",
intended to be in |
pkg |
If |
The result of evaluating infix(expr)
in the specified
environment.
Because R is a Scheme dialect under the hood, prefix or Lisp-like R is still
valid R code and parses with the built-in R parser. All of R's rules about
syntactic names (see make.names
) still apply, and these rules
are stricter than usual among Lisps.
Because our prefix syntax is just a preprocessing step (R code expressed
with the .
function is transformed into its usual infix
form before evaluation), R's function-call mechanism is still used exactly
as-is. In particular, it's still not possible to do tail call elimination
safely for arbitrary functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 | schemeR::schemeR({
.(let, .(.(x, .(c, 1, 3, 5, 7, 9))),
.(do, .(.(x, .(c, 1, 3, 5, 7, 9), .(cdr, x)),
.(s, 0, .(`+`, s, .(car, x))),
.(foo, 4)),
.(.(is.nil, x), s)))
}, pkg=TRUE) #=> 25
require(schemeR)
schemeR({
.(define, x, .(sort, .(sample, .(`:`, 1, 10), 5, replace=TRUE)))
.(`for`, i, x, .(print, .(`:`, 1, i)))
})
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.