Search code examples
rtidyversereadr

How to correctly print μ by write_csv?


write_csv() in readr outputs μ as µ. How to correctly output μ using write_csv()?

library(tidyverse)
x <- tribble(~x, 'µ')
write_csv(x, 'test.csv')

enter image description here


Solution

  • write_csv() will work correctly when the characters in tibble are in raw byte with UTF-8 Encoding.

    library(tidyverse)
    x <- tribble(~x, '\xb5')
    Encoding(x$x) <- 'UTF-8'
    write_csv(x, 'test.csv')