Performs one conditional threading pass. Carefully examine the results after running this function!
opt_cond_thread(code)
code | A list of character vectors with the code to optimize. |
---|
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]])#> 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 #> odd_num_b <- odd_num_b + num #> }else { #> even_sum <- even_sum + num #> }