5
library(readr)

Disease<-read_csv(file = "C:/Users/bryan/Documents/Data Science 
Project/CT5163_Project_2021_22_Disease_final.csv")

ForestFire<-read_csv(file = "C:/Users/bryan/Documents/Data Science 
Project/CT5163_Project_2021_22_ForestFire_final.csv")

Salary<-read_csv(file = "C:/Users/bryan/Documents/Data Science 
Project/CT5163_Project_2021_22_Salary_final.csv")

The first two files read perfectly with no issues. however with the salary_final.csv, when read , an error comes back with the following "Error in nchar(x, "width") : invalid multibyte string, element 1"

Anyone know why and what i can do to fix this?

mb67
  • 51
  • 1
  • 1
  • 6
  • 1
    Have you tried with other reading funcs, as in `data.table::fread`, `utils::read.csv`, or `vroom::vroom`? – r2evans Mar 18 '22 at 20:49
  • 5
    Where did the CSV file come from? Do you know what character encoding the file uses? You might want to ask whomever gave you the file to see what encoding you should be using to read in the files. Maybe try `locale=locale(encoding="latin1")` in the call to `read_csv`? It's hard to say for sure without some sort of [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Mar 18 '22 at 20:49
  • You are missing an ending parentheses on the Salary_final.csv – Daniel L Mar 18 '22 at 20:54
  • 1
    hey, i tried locale=locale(encoding="latin1") and it worked ! thanks man. – mb67 Mar 18 '22 at 20:56
  • yeah i saw that, still get the same message when i fixed that. not having locale=locale(encoding="latin1") was the problem. – mb67 Mar 18 '22 at 20:58

2 Answers2

15

Try

locale=locale(encoding="latin1")

in the call to read_csv

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Dubukay
  • 1,764
  • 1
  • 8
  • 13
  • 1
    Wow this situation is truly bizarre. But this solution worked like magic for me! Thank you! Without this I would have had no chance in a million years of figuring that out. – James Cutler Oct 16 '22 at 19:33
0

i had the same problem with a local CSV. I fix it using locale=locale(encoding="latin1") in the call read_csv.