4

When a parameter of a function is a string rather than a quosure (e.g. from a Shiny UI) I can think of 2 options to use it in a dplyr::mutate call:

  1. string -> quosure

    library(dplyr)
    var <- "am"
    mtcars %>% mutate(!!rlang::sym(var) := !!rlang::sym(var) + 1)
    
  2. mutate_at

    library(dplyr)
    var <- "am"
    mtcars %>% mutate_at(var, funs(. + 1))
    

Is there any reason to prefer one of the other? Are there any border cases which I may not be aware of? For consistency I want to stick to one option and I need to decide which one I should choose. Option 2 needs less dependencies, but I want to eb sure that both variants are indeed identical.

thothal
  • 16,690
  • 3
  • 36
  • 71
  • 1
    Conceptually, using `mutate_at` limits your options to updating one or more existing variables whereas `mutate` also allows you to add new variables, as far as I know. There may be other differences, but this one might be relevant, too. – talat Jul 11 '18 at 12:57

0 Answers0