1

In dplyr 0.8.0, funs() is deprecated, and the new format is to use list() with ~. However, I have noticed that this no longer updates columns using mutate_at() as previously expected.

> set.seed(5)
> testdf <- data.frame(a = sample(1:9, size = 5, replace = TRUE),
+                      b = 1:5,
+                      c = LETTERS[1:5])
> testdf
  a b c
1 2 1 A
2 7 2 B
3 9 3 C
4 3 4 D
5 1 5 E

Example of old code:

> testdf %>% mutate_at(.vars = c('a','b'), .funs = funs(. + 2))
   a b c
1  4 3 A
2  9 4 B
3 11 5 C
4  5 6 D
5  3 7 E

Example of new code:

> testdf %>% mutate_at(.vars = c('a','b'), .funs = lst(~. + 2))
  a b c a_~. + 2 b_~. + 2
1 2 1 A        4        3
2 7 2 B        9        4
3 9 3 C       11        5
4 3 4 D        5        6
5 1 5 E        3        7

EDIT: I just noticed that if I use list() this problem is resolved:

> testdf %>% mutate_at(.vars = c('a','b'), .funs = list(~. + 2))
   a b c
1  4 3 A
2  9 4 B
3 11 5 C
4  5 6 D
5  3 7 E

However, I wish to use lst() because within my code I regularly requiring unquoting variables using !!!, which is not supported by list() (see here)

I'm not sure of the proper way to use lst() while retaining the names.

Brandon
  • 1,722
  • 1
  • 19
  • 32

1 Answers1

3

rlang::list2

is equivalent to list(...) but provides tidy dots semantics:

>  testdf %>% mutate_at(.vars = c('a','b'), .funs = rlang::list2(~. + 2))
   a b c
1  4 3 A
2  9 4 B
3 11 5 C
4  5 6 D
5  3 7 E
Richard Telford
  • 9,558
  • 6
  • 38
  • 51