[R] Reading in a table with ISO-latin1 encoding in MacOS-X (Intel)

Antti Arppe aarppe at ling.helsinki.fi
Thu Jun 8 15:10:08 CEST 2006


Dear colleages in R,

I have earlier been working with R in Linux, where reading in a table 
containing Scandinavian letters ("ä", "ö", and "å") in the header as 
part of variable names has not caused any problem whatsoever.

However, when trying to do the same in R running on new MacOS-X (with 
an Intel processor) with the same original text table does not seem to 
work whichever way I try. Following the recommendations on the R site 
and using the 'file' function to set the encoding breaks down at the 
first encounter with a Scandinavian character:

THINK <- read.table(file("R_data/hs+sfnet.T.060505.tbl4", 
encoding="latin1"),header=TRUE)
Warning messages:
1: invalid input found on input connection 
'R_data/hs+sfnet.T.060505.tbl4'
2: incomplete final line found by readTableHeader on 
'R_data/hs+sfnet.T.060505.tbl4'

A sample exemplifying such characters as variable labels is below 
(for which the behavior of R in Mac is the same as for the larger file 
referred to above):.

    ajatella miettiä pohtia
1     FALSE   FALSE   TRUE
2     FALSE   FALSE  FALSE
3     FALSE    TRUE  FALSE
4     FALSE    TRUE  FALSE
5      TRUE   FALSE  FALSE
6      TRUE   FALSE  FALSE
7     FALSE   FALSE  FALSE
8     FALSE    TRUE  FALSE
9     FALSE    TRUE  FALSE
10    FALSE   FALSE  FALSE

Converting the the file from ISO-latin-1 to UTF8 (with Mac's TextEdit 
application)allows the file to be read in in its entirety, but still 
the Scandinavian character in the heading is coerced to a period '.', 
or two, in fact (i.e. 'miettiä' -> 'miett..')

Have I possibly misunderstood how the 'file' function should be used 
in conjunction with 'read.table', or might the problem with 
latin1-to-utf conversion be somewhere else?

Appreciating any help on this matter,

-- 
======================================================================
Antti Arppe - Master of Science (Engineering)
Researcher & doctoral student (Linguistics)
E-mail: antti.arppe at helsinki.fi
WWW: http://www.ling.helsinki.fi/~aarppe


More information about the R-help mailing list