1

I have an issue with loading data between default encoding on Win and nix machines (ISO-8859-1 and UTF-8 respectively).

Example - Windows first:

library(stringi)
dummy <- as.character("BØÅS")
write(dummy, "saveFile")
getData <- read.table("saveFile", header=F, sep="\t", quote="\"")

reEncode=function(x) {
  stri_trans_general(x, "Latin-ASCII")
}

enCoded  <- apply(getData, 1, reEncode)
result   <- as.data.frame(enCoded)

In Windows the above produces "BOAS" as desired.

Now move to nix and use the saved file:

getData <- read.table("saveFile", header=F, sep="\t", quote="\"")

    reEncode=function(x) {
      stri_trans_general(x, "Latin-ASCII")
    }

    enCoded  <- apply(getData, 1, reEncode)
    result   <- as.data.frame(enCoded)

Nix gives "B??S".

I believe this is a read.table encoding issue but haven't been able to figure out how to get nix to use ISO-8859-1. Any suggestions?

4

1 回答 1

0
read.table("saveFile", header=F, sep="\t", quote="\"",encoding="latin1")
于 2015-05-28T13:30:52.367 回答