factor_mutate: Re-write a 'dplyr::mutate()' into safe blocks.

Description Usage Arguments Value Examples

View source: R/stmtPlanner.R

Description

Note: not for use with rlang expressions (guesses variable names by text inspection). See also: https://winvector.github.io/rquery/articles/AssigmentPartitioner.html.

Usage

1
factor_mutate(..., factor_mutate_warn_msg = TRUE)

Arguments

...

mutate terms

factor_mutate_warn_msg

logical if TRUE issue a warning message on non-trivial mutates.

Value

partitioned dplyr::mutate() source text

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cat(factor_mutate(
 choice_a = rand_a >= 0.5,
   a_1 = ifelse(choice_a, 'T', 'C'),
   a_2 = ifelse(choice_a, 'C', 'T'),
  choice_b = rand_b >= 0.5,
   b_1 = ifelse(choice_b, 'T', 'C'),
   b_2 = ifelse(choice_b, 'C', 'T'),
  choice_c = rand_c >= 0.5,
   c_1 = ifelse(choice_c, 'T', 'C'),
   c_2 = ifelse(choice_c, 'C', 'T'),
  choice_d = rand_d >= 0.5,
   d_1 = ifelse(choice_d, 'T', 'C'),
   d_2 = ifelse(choice_d, 'C', 'T'),
  choice_e = rand_e >= 0.5,
   e_1 = ifelse(choice_e, 'T', 'C'),
   e_2 = ifelse(choice_e, 'C', 'T'),
 factor_mutate_warn_msg = FALSE ))

cat(factor_mutate(
 choice = rand_a >= 0.5,
   a_1 = ifelse(choice, 'T', 'C'),
   a_2 = ifelse(choice, 'C', 'T'),
  choice = rand_b >= 0.5,
   b_1 = ifelse(choice, 'T', 'C'),
   b_2 = ifelse(choice, 'C', 'T'),
  choice = rand_c >= 0.5,
   c_1 = ifelse(choice, 'T', 'C'),
   c_2 = ifelse(choice, 'C', 'T'),
  choice = rand_d >= 0.5,
   d_1 = ifelse(choice, 'T', 'C'),
   d_2 = ifelse(choice, 'C', 'T'),
  choice = rand_e >= 0.5,
   e_1 = ifelse(choice, 'T', 'C'),
   e_2 = ifelse(choice, 'C', 'T'),
 factor_mutate_warn_msg = FALSE))

seplyr documentation built on Sept. 5, 2021, 5:12 p.m.