opt_cond_thread: Optimizer: Conditional Threading.

View source: R/opt-cond-thread.R

opt_cond_threadR Documentation

Optimizer: Conditional Threading.

Description

Performs one conditional threading pass. Carefully examine the results after running this function!

Usage

opt_cond_thread(code)

Arguments

code

A list of character vectors with the code to optimize.

Examples

code <- paste(
  "num <- sample(100, 1)",
  "even_sum <- 0",
  "odd_sum_a <- 0",
  "odd_sum_b <- 0",
  "if (num %% 2 == 1) {",
  "  odd_sum_a <- odd_sum_a + num",
  "}",
  "if (num %% 2 == 1) {",
  "  odd_num_b <- odd_num_b + num",
  "}",
  "if (!(num %% 2 == 1)) {",
  "  even_sum <- even_sum + num",
  "}",
  sep = "\n"
)
cat(opt_cond_thread(list(code))$codes[[1]])

jcrodriguez1989/rco documentation built on Nov. 12, 2024, 12:23 p.m.