OEM-866 (キリル文字セット) としてエンコードされた CSV を Windows の R にインポートしようとしています。BOMなしでUTF-8に変換されたコピーもあります。これらのファイルは両方とも、エンコーディングを指定すると、システム上の他のすべてのアプリケーションで読み取ることができます。
さらに、Linux では、R は指定されたエンコーディングでこれらの特定のファイルを問題なく読み取ることができます。「fileEncoding」パラメーターを指定しない場合、Windows で CSV を読み取ることもできますが、テキストが読み取れなくなります。Windows でファイル エンコーディングを指定すると、OEM ファイルと Unicode ファイルの両方で常に次のエラーが発生します。
元の OEM ファイルのインポート:
> oem.csv <- read.table("~/csv1.csv", sep=";", dec=",", quote="",fileEncoding="cp866") #result: failure to import all rows
Warning messages:
1: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
invalid input found on input connection '~/Revolution/RProject1/csv1.csv'
2: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
number of items read is not a multiple of the number of columns
BOM ファイルのインポートなしの UTF-8:
> unicode.csv <- read.table("~/csv1a.csv", sep=";", dec=",", quote="",fileEncoding="UTF-8") #result: failure to import all row
Warning messages:
1: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
invalid input found on input connection '~/Revolution/RProject1/csv1a.csv'
2: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
number of items read is not a multiple of the number of columns
ロケール情報:
> Sys.getlocale()
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
これに責任があるのは、Windows上のRについて何ですか? この時点で、ウィンドウを捨てる以外に、できることはほとんどすべて試しました。
ありがとうございました
(追加の試行失敗):
>Sys.setlocale("LC_ALL", "en_US.UTF-8") #OS reports request to set locale to "en_US.UTF-8" cannot be honored
>options(encoding="UTF-8") #now nothing can be imported
> noarg.unicode.csv <- read.table("~/Revolution/RProject1/csv1a.csv", sep=";", dec=",", quote="") #result: mangled cyrillic
> encarg.unicode.csv <- read.table("~/Revolution/RProject1/csv1a.csv", sep=";", dec=",", quote="",encoding="UTF-8") #result: mangled cyrillic