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

View source: R/stmtPlanner.R

factor_mutateR Documentation

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

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

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


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))


WinVector/seplyr documentation built on Aug. 26, 2022, 12:01 p.m.