Stack Exchange
R - Error in doc_parse_file
I ran into the following Error message today, and I struggle to fix it (google doesn't help me out here :/ ):
Error in doc_parse_file(con, encoding = encoding, as_html = as_html, options = options) : 
  Input is not proper UTF-8, indicate encoding !
Bytes: 0xFC 0x74 0x7A 0x74 [9]

Ran into it, while I was reading in and processing 230+ mhtml files (.mht). I read in the data using the following way: 
convertToFile <- function(path){
  conn <- file(path,open="r")
  lines <- readLines(conn)
  zzzz <- data.frame(Text=rep(NA,length(lines)))
  for (i in 1:length(lines)){
    zzzz[i,] <- lines[i]
  }
  close(conn)

and:
  temp <- read_html(path)
  var_i <- html_table(temp)
  var_infos <- merge (var_i[2],var_i[4], all = TRUE)

I find the files by using this code (could be relevant):
dirs_1 <- list.dirs(path=i,recursive = FALSE)
  for(j in dirs_1){
    temp <- list.files(j)
    temp <- temp[which(grepl("tan-delta-Diagnose",temp,ignore.case = TRUE)==TRUE)[1]]
    temp1 <- convertToFile(gsub(pattern = "/","\\\\",paste0(j,"\\",temp)))

(this is the most bottom layer, otherwise I grab them using the same method, via list.dirs)
Has anybody a clue how to fix this issue? 
Note: I only got this error after 60ish files. 
Sys.settings:
"LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252"


Found the problem (and the solution) for this. Although I used rvest (and thus shouldn't be bound to the encoding issues), the read_html didn't work with the ISO-8859-1encoding. 
Adapting the second input line to the following: 
temp <- read_html(path, encoding = "ISO-8859-1")
var_i <- html_table(temp)
...

fixed the issue. 
To find the encoding guess_encoding('file name', n = 1000) was used. 
NOTE: This only works, if you have only a single other encoding along the UTC-8 one.
Tl;dr: Change the encoding from the read_html when you run into this problem. 
