Brandon.J.Whitcher at gsk.com
2006-Apr-27 17:21 UTC
[R] Error in readChar(): invalid UTF-8 input
I have R code to read a binary header file, consisting of several readBin() and readChar() statements. I am currently using version R-2.2.1 (on x86_64, RH EL4) and have received the following error Error in readChar(fid, n = 1) : invalid UTF-8 input in readChar() This is strange because (a) I was able to read in this file successfully in previous versions of R (circa 2005) and (b) it doesn't fail all the time; i.e., other readChar() statements work. When I access the header file using a different piece of software, it gives the value "-1" for the field. What's going on? cheers... Brandon [[alternative HTML version deleted]]
On 4/27/2006 1:21 PM, Brandon.J.Whitcher at gsk.com wrote:> I have R code to read a binary header file, consisting of several > readBin() and readChar() statements. I am currently using version R-2.2.1 > (on x86_64, RH EL4) and have received the following error > > Error in readChar(fid, n = 1) : invalid UTF-8 input in readChar() > > This is strange because (a) I was able to read in this file successfully > in previous versions of R (circa 2005) and (b) it doesn't fail all the > time; i.e., other readChar() statements work. > > When I access the header file using a different piece of software, it > gives the value "-1" for the field. > > What's going on?Probably the older versions of R were not trying to interpret the field as UTF-8: that's locale-dependent, and a relatively recent addition. Not all byte sequences are legal UTF-8 encodings, and it sounds as though R is trying to tell you that yours is not. To say more than this would require lots more information from you, for example a reproducible example. Can you write the same bytes that are in that field into a file by themselves, and read that file? Can you read the file using the current version of R (2.3.0)? What about on other platforms? Duncan Murdoch