0

I'm reading a .csv file with encoding UTF-8:

orden_cat <- read.csv("Input/Orden de categorias.csv", sep=";", encoding="UTF=8", stringsAsFactors = FALSE)

However, it doesn't read the spanish accents well anyway:

enter image description here

And also when I try to save the script, it gives me this "error":

enter image description here

Before all these errors, I copied and pasted the Rproject in a new address (with all the files and sub-carpets. I have related addresses, so what could be the problem?

Chris
  • 2,019
  • 5
  • 22
  • 67
  • I have also worked with spanish accents/ñ/etc. before and have been able to do so using text encoding `ISO8859-1` – boski Mar 05 '19 at 14:46
  • It doesn't work. – Chris Mar 05 '19 at 15:10
  • Are you sure the file is actually encode as UTF-8?? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 05 '19 at 15:17
  • If you mean File -> "Save with Encoding" and the UTF-8 option is shaded (as when I use "Reopen with Encoding"), then it is encoded as UTF-8. I don't know how to make a reproducible example for this case, as if I write something in spanish in the console and save it in a variable, it saves it correctly. The problem is just reading the .csv file. – Chris Mar 05 '19 at 15:23
  • 2
    Are you sure that it's UTF-8? You might be able to find the encoding with `readr::guess_encoding` https://rdrr.io/cran/readr/man/encoding.html Or provide a sample file. – amatsuo_net Mar 05 '19 at 15:42
  • Thanks ! It's not. It's 100% ASCII. How do I change this encoding if I'm reading with UTF-8 in read.csv()? – Chris Mar 05 '19 at 15:54

1 Answers1

0

Solved! The problem was Orden de categorias.csv was saved as .csv with UTF-8 encoding, and if I save it as just .csv it works perfectly.

Chris
  • 2,019
  • 5
  • 22
  • 67