title: How to change encding of column names to utf 8 in R
body: <p>I've got a daata frame with Russian <code>colnames</code> in UTF-8. I do some lineer modeling with <code>purrr</code> and explore <code>coefficients</code> with <code>broom::tidy()</code>, then I receive a data frame with mixed column name encodings, which I cant pass to <code>girafe()</code>, it crushes with an error.</p>
  
  <p>I've tried to use <code>stringi::stri_enc_toutf8(colnames(df))</code>: doesn't help</p>
  
  <p>`Encoding(colnames(df)) &lt;- "UTF-8" doesn't help</p>
  
  <pre><code>rem %&gt;% 
     group_by(МАГАЗИН, `ТИП МАГАЗИНА`, Дата) %&gt;% 
     summarise(`Количество, шт` = sum(`Количество, шт`, na.rm = TRUE)) %&gt;% 
     select(МАГАЗИН, `ТИП МАГАЗИНА`, `Количество, шт`, Дата) %&gt;% 
     group_by(`ТИП МАГАЗИНА`, МАГАЗИН) %&gt;% 
     nest() %&gt;% 
     mutate(lm = map(data, ~lm(formula = `Количество, шт` ~ Дата, data = .x)),
            fit = map(lm, tidy)) %&gt;% 
     unnest(fit) %&gt;% 
     filter(term != "(Intercept)") %&gt;% 
     colnames() %&gt;% Encoding()
  [1] "UTF-8"   "UTF-8"   "unknown" "unknown" "unknown" "unknown" "unknown"
  &gt; 
  
  </code></pre>
  
  <p>and than, when I plot it, I've got this:</p>
  
  <pre><code>girafe_options(
     girafe( code = print(
  
       rem %&gt;% 
         group_by(МАГАЗИН, `ТИП МАГАЗИНА`, Дата) %&gt;% 
         summarise(`Количество, шт` = sum(`Количество, шт`, na.rm = TRUE)) %&gt;% 
         select(МАГАЗИН, `ТИП МАГАЗИНА`, `Количество, шт`, Дата) %&gt;% 
         group_by(`ТИП МАГАЗИНА`, МАГАЗИН) %&gt;% 
         nest() %&gt;% 
         mutate(lm = map(data, ~lm(formula = `Количество, шт` ~ Дата, data = .x)),
                fit = map(lm, tidy)) %&gt;% 
         unnest(fit) %&gt;% 
         filter(term != "(Intercept)") %&gt;% 
         mutate(term = "Дата")  %&gt;%
         ggplot(aes(x = reorder(МАГАЗИН, estimate), y = estimate,col = `ТИП МАГАЗИНА` , shape = `ТИП МАГАЗИНА` )) +
         geom_point_interactive(aes(tooltip = paste("Изменение: ", round(estimate, 6), "&lt;br&gt;",
                                                    "Среднеквадратическое отклонение: ", round(std.error, 6), "&lt;br&gt;",
                                                    "ВВероятность случайного изменения: ", round(p.value, 6)))) +
         geom_errorbar(aes(x = reorder(МАГАЗИН, estimate), ymin = estimate - (estimate + 1.96*std.error), 
                           ymax = estimate + (estimate + 1.96*std.error)))+
         geom_segment(aes(y = 0, yend = estimate, xend = МАГАЗИН)) +
         geom_hline(yintercept = 0, col = "black", size = 0.4, linetype = "dashed")+
         coord_flip() +
         theme_light() +
         theme(text = element_text(size = 16)) +
         theme(axis.text.x = element_text(angle = 90, vjust = 1)) +
         theme(legend.position='bottom', 
               legend.justification='left',
               legend.direction='horizontal')+
         labs(title = "Выручка и количество проданных товаров Реми и Экономыча",
              subtitle = "по номенклатуре",
              y = "",
              x = "Номенклатура")),height_svg = 2, width_svg = 16),opts_tooltip(use_fill = TRUE), opts_zoom(max = 5))
  
  
  Error in doc_parse_file(con, encoding = encoding, as_html = as_html, options = options) : 
    Input is not proper UTF-8, indicate encoding !
  Bytes: 0xC8 0xE7 0xEC 0xE5 [9]
  
  </code></pre>
  
  <p>on a simulated dataset:</p>
  
  <pre><code>
  
  x &lt;- seq.Date(as.Date("2010-01-01"), as.Date("2018-12-01"), "months")
  
  
  
  y &lt;- c(arima.sim(model = list(order = c(2,1,1), ar = c(1.5, -0.75), ma = 15), n = 107, sd = 15 ),
         arima.sim(model = list(order = c(2,1,1), ar = c(1.5, -.95), ma = 11), n = 107, sd = 15 ),
         arima.sim(model = list(order = c(4,0,1), ar = c(0.8, -.75, 0.6, 0.3), ma = 32), n = 108, sd = 10))
  
  
  df &lt;- data.frame(Дата = rep(x,3), y = y, Группа = c(rep("G1", 108), rep("G2", 108),rep("G3", 108)))
  
  
  </code></pre>
  
  <p>everithing works just fine, but all the encodings are the same</p>
  
  <pre><code>stringi::stri_enc_mark(colnames(df))
  [1] "native" "ASCII"  "native"
  </code></pre>
  
  <p>How can i change the encoding so that i can plot it?</p>