How to show unicode characters when I use vroom?

I would like to edit this function so when i open the file i can view properly

df <- tibble(x = c("a", "\U00f4"), y = 1:2)
header <- Sys.Date()

fun <- function(x, header = NULL, file){
  if (!is.null(header)) vroom_write_lines(as.character(header), file, append = TRUE)
  vroom_write(x, file, delim = ",", col_names = TRUE,  append = TRUE)

### Test the function ####
fun(df, NULL, "test.csv.gz")
fun(df, header, "test.csv.gz")

I don't understand the problem.

> readLines("test.csv.gz")
[1] "x,y"        "a,1"        "ô,2"        "2022-12-01" "x,y"       
[6] "a,1"        "ô,2"

Is that not your expected result? Are you getting something different?

If you are getting the wrong result in Excel (a ô instead of ô), it's a problem with Excel, go to the Data tab, select "From Text/CSV", and in the import window you can choose the encoding.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.