yutannihilation · GitHub

I've faced this behavior with R 3.3.2 and dplyr 0.5.0 on my Windows machine.

d <- data.frame("φ" = 1:10)
Encoding(colnames(d))
#> [1] "unknown"
d2 <- d %>% select(φ)
Encoding(colnames(d2))
#> [1] "UTF-8"

This is due to this tricky behavior of c() function in the base R; The names of named vectors are converted to UTF-8 accidentally.

x <- "φ"
names(x) <- "φ"
Encoding(names(x))
#> [1] "unknown"
Encoding(names(c(x)))
#> [1] "UTF-8"

This problem itself is not so problematic and not dplyr's fault, but until #1950 is solved we will continue to see the error with functions like group_by() and distict(). (e.g. #2277, #2005)

d %>%
  select(φ) %>%
  group_by(φ)
#> Error in grouped_df_impl(data, unname(vars), drop) : unknown column 'φ' 

So, could you consider to stop using c() here?: https://github.com/hadley/dplyr/blob/1ba25c03826372f41e7d7b850a174d881f0ac15b/R/select-vars.R#L86

Read the original on github.com ↗