I am trying to run assembly () in data frames and programmatically assign a .key column name using !! quo (). But I keep getting "Error: invalid column specification." I even found a private ticket where it shows that it should work ( https://github.com/tidyverse/tidyr/issues/293 ).
I'm going to get back to using rename_ () as a workaround, but it would be nice to use a more elegant NSE.
library('tidyverse')
data(mtcars)
my_var <- 'my_col_name'
Following works but this is a one-way pony
> mtcars %>%
as_tibble %>%
rownames_to_column('car_make') %>%
gather(my_col_name, values, -car_make)
car_make my_col_name values
<chr> <chr> <dbl>
1 Mazda RX4 mpg 21.0
2 Mazda RX4 Wag mpg 21.0
3 Datsun 710 mpg 22.8
4 Hornet 4 Drive mpg 21.4
5 Hornet Sportabout mpg 18.7
6 Valiant mpg 18.1
7 Duster 360 mpg 14.3
8 Merc 240D mpg 24.4
9 Merc 230 mpg 22.8
10 Merc 280 mpg 19.2
The following attempts to use tidyeval two give the same error:
> mtcars %>%
as_tibble %>%
rownames_to_column('car_make') %>%
gather(!!quo(my_var), values, -car_make)
Error: Invalid column specification
> mtcars %>%
as_tibble %>%
rownames_to_column('car_make') %>%
gather(!!enquo(my_var), values, -car_make)
Error: Invalid column specification
Library options
tidyverse_1.1.1
dplyr_0.7.0
tidyr_0.6.3
rlang_0.1.1
source
share