View source: R/opt-common-subexpr.R
opt_common_subexpr | R Documentation |
Performs one common subexpression elimination pass. Carefully examine the results after running this function!
opt_common_subexpr(texts, n_values = 2, in_fun_call = FALSE)
texts |
A list of character vectors with the code to optimize. |
n_values |
A numeric indicating the minimum number of values to consider a subexpression. |
in_fun_call |
A logical indicating whether it should propagate in function calls. Note: this could change the semantics of the program. |
code <- paste(
"a <- b * c + g",
"d = b * c * e",
sep = "\n"
)
cat(opt_common_subexpr(list(code))$codes[[1]])
heron_formula <- paste(
"area <- (a/2 + b/2 +c/2) * (a/2 + b/2 + c/2 - a) * (a/2 + b/2 + c/2 - b) *",
" (a/2 + b/2 + c/2 - c)",
"area <- sqrt(area)",
sep = '\n'
)
cat(opt_common_subexpr(list(heron_formula))$codes[[1]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.