Skip to content

mutate_all() and UTF-8 names #2967

@krlmlr

Description

@krlmlr
library(magrittr)
suppressPackageStartupMessages(library(dplyr))

data_frame(a = 1) %>%
  setNames(enc2native("\u4e2d")) %>%
  mutate_all(funs(as.character))
#> # A tibble: 1 x 2
#>   `<U+4E2D>`  `中`
#>        <dbl> <chr>
#> 1          1     1

data_frame(a = 1) %>%
  setNames("\u4e2d") %>%
  mutate_all(funs(as.character))
#> Warning: Mangling the following names: <U+4E2D> -> <U+4E2D>. Use
#> enc2native() to avoid the warning.
#> Error in mutate_impl(.data, dots): Evaluation error: variable '<U+4E2D>' not found.

(I did manually change the output for the first example to include the Chinese character.)

In the first example, mutate_all() gets a data frame with Unicode-escaped column names at input. Do we want to repair encoding in column names for each dplyr verb?

In the second example, the column name is properly UTF-8 encoded, but r-lib/rlang@ff87439 seems to get confused.

CC @lionel-.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions