0

I have a fixed width file that I am reading in this way:

library(readr)
mydata <- read.fwf(file="myfile.txt", widths = c(12, 7, etc))

It returns:

Error in substring(x, first, last) : 
  invalid multibyte string at '<cd>S    '

As the file is pretty big I would like to find out what is the line number in the file that returns the error. How can I get that using R?

Randomize
  • 8,651
  • 18
  • 78
  • 133
  • try `mydata <- read.fwf(file="myfile.txt", widths = c(12, 7, etc), fileEncoding="latin1")`? Try searching on the error `invalid multibyte string` as there are lots of other SO questions relating to this – dpel Sep 20 '16 at 14:48
  • thank you. It fixed the issue using ```latin1``` as encoding so I can parse the whole file. However I am still wondering if there is a way to get the line number that creates the problem. – Randomize Sep 20 '16 at 15:03

0 Answers0