Description Usage Arguments Details Value References Examples
Expects an expression in (reverse) polish notation as a character vector and returns the expression in infix notation and the evaluated expression.
1 2 |
rpn.expr |
[ |
reverse |
[ |
eval |
[ |
clean |
[ |
vars |
[ |
ops |
[ |
This is a pure R implementation.
List with the components
Infix representation of rpn.expr.
Evaluated expression or NA if eval is set to FALSE.
Lukasiewicz, Jan (1957). Aristotle's Syllogistic from the Standpoint of Modern Formal Logic. Oxford University Press.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # simple example
r = c("4", "6", "*", "6", "+")
rpn(r)
rpn(r, eval = FALSE)
# the same example but with a variable
r = c("x", "6", "*", "6", "+")
rpn(r, eval = TRUE, vars = list(x = 4))
rpn(r, eval = FALSE)
# now a more complex expression with variables and custom operators/functions
rpe = c("x", "5", "6.4", "mysum", "5", "mystuff")
mysum = function(x, y, z) x + y + z # arity 3 and no infix operation
mystuff = function(x, y) 2 * (x + y) # arity 2 and no infix operation
ops = list(mysum = list(3, FALSE, mysum), mystuff = list(2, FALSE, mystuff))
vars = list(x = 3.6)
res = rpn(rpe, ops = ops, vars = vars)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.