Learn R Programming

seplyr (version 1.0.4)

factor_mutate: 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

Run this code
# NOT RUN {
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))

# }

Run the code above in your browser using DataLab