Get Started →
File & Connection Errors

Encoding / iconv error

Matches: cannot convert|invalid byte sequence

WHAT THIS ERROR MEANS

R encountered characters in an encoding it can't handle. The file may use a different encoding than expected (e.g., Latin-1 vs UTF-8).

HOW TO FIX IT

1. Specify the encoding: read.csv('file.csv', fileEncoding = 'latin1').

2. Use readr::read_csv() with locale(encoding = '...').

3. Convert encoding with iconv(x, from = 'latin1', to = 'UTF-8').

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
read.csv("european_data.csv")  # file is latin1 encoded
GOOD — CORRECT APPROACH
read.csv("european_data.csv", fileEncoding = "latin1")
# or
readr::read_csv("european_data.csv",
  locale = readr::locale(encoding = "latin1"))

Still stuck?

Paste your code in RChat and the AI will fix this error in context.

Try RChat Free →

RELATED FILE & CONNECTION ERRORS