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(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.