Iterating with scoped dplyr verbs

Quite often I find myself wanting to apply a scoped dplyr verb (*_at, etc.) on several datasets. My first instinct is always to simply map over a list of my data frames, like so:

library(tidyverse)

dfs <- list(iris, trees)
map(dfs, rename_all, tolower)

However, this results in the following cryptic error message:

# Error in (function (x, strict = TRUE)  :
#   the argument has already been evaluated

I usually work around this using the handy formula-to-function conversion shortcut in map: map(dfs, ~ rename_all(., tolower)) However, whenever I do this, it always makes me cringe a little bit; I feel like my code is not as neat as it could be.

Am I missing something obvious here? Is this expected behaviour? I've searched through SO, dplyr github issues, and the forum here, to no avail. I'd be grateful for any insights as to why my first approach isn't working (but my workaround is) -- and more elegant solutions would be very welcome, too.

If you install the development version of rlang it solves the problem. You can do that by the following piece of code assuming that devtools is installed.

devtools::install_github("tidyverse/rlang")

Remember to restart your R session before evaluating the code.

2 Likes

Ah, thanks @elben10. I'm still curious as to what's the issue in the released version, but I suspect that will remain a mystery :sweat_smile: