RStudio and utf-8 giving problems

Hi
I have set the global and project options in RStudio to UTF-8. In the editor my script (UTF-8) shows correctly (last line of code below).

publ <- as_tibble(read.xlsx(info_file, "Tabellen", startRow = 2, )) %>%
  fill(nr, .direction = c("down")) %>%
  fill(Nom.du.paquet.GNP, .direction = "down") %>%
  rename(excel_file = Liste.tableaux.liés.au.paquet.GNP,

However, if I run the code I get the following error:

Error in source(paste0("./00_setup/00_", publ_year, "_setup.R")) : 
  ./00_setup/00_2022_setup.R:101:41: unexpected input
100:   fill(Nom.du.paquet.GNP, .direction = "down") %>%
101:   rename(excel_file = Liste.tableaux.lié

If I overwrite the "é" in my RScript and run it again, there is no problem until I restart RStudio and I am back again with the same problem.
If I ask for the encoding set in RStudio, I get

> options("encoding")
$encoding
[1] "native.enc"

I am using RStudio 1.4.1106 (can't update as it is my work computer).

Any help would be appreciated.
Cheers
Renger

Hi
I found the answer: the problem was that I sourced the file with

source("myfile.R")

Changing this to

source("myfile.R",  encoding="utf-8")

solved the problem.
Cheers
Renger

1 Like

This topic was automatically closed 7 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.