[R] use of Encoding()?

David Winsemius dwinsemius at comcast.net
Fri Feb 3 20:23:02 CET 2017


> On Feb 3, 2017, at 10:12 AM, Olivier Crouzet <olivier.crouzet at univ-nantes.fr> wrote:
> 
> Hi,
> 
> using R version 3.3.2 under Linux, these work perfectly (but I receive
> a correct encoding ("UTF-8"), not "unknown"). 
> 
> What is your system (windows, mac, linux)? Your R version? Which
> interface (RStudio, Windows R interface)? There are often issues with
> character encoding using Windows (in many different programming
> languages) but it may not be the case concerning R.

I'm wondering if it's being done on a Mac, since I see the same behavior at my console (the "standard" R.app GUI). If the issue is with reading a Windows file while using one of the `read.*` functions, then setting the `fileEncoding` parameter to one of 'iso-8859-1' or 'cp1252' may be attempted.

The ?Encodings page says: "ASCII strings will never be marked with a declared encoding, since their representation is the same in all supported encodings."

Running the example in the help page (on a Mac):

> x <- "fa\xE7ile"
> Encoding(x)
[1] "unknown"
> Encoding(x) <- "latin1"
> x
[1] "façile"
> Encoding(x)
[1] "latin1"


-- 
David.
> 
> If these operations are meant to read data from a file, you may
> alternatively consider the option fileEncoding= from read.table /
> read.csv (to change encoding) or, perhaps but I would
> suggets first trying the preceding option, encoding= (to specifically
> declare the file encoding if you know it but R does not detect it).
> 
> Olivier.
> 
> 
> On Fri, 3 Feb 2017 17:29:20 +0100 Tilmann Faul
> <Tilmann_Faul at t-online.de> wrote:
> 
>> Hey,
>> 
>> this is my first question here, so forgive me if i my be clumsy.
>> 
>> I want  to use Encoding to set the encoding of a character vector, but
>> it doese not seem to work. See example.
>> 
>>> x <- "16-03-02"
>>> Encoding(x)
>> [1] "unknown"
>>> Encoding(x) <- "latin1"
>>> Encoding(x)
>> [1] "unknown"
>> 
>> Is this intended?
>> Actually i want to change encoding of a character vector generated by
>> list.file on a linux computerwith UTF-8 file encoding, rstudio
>> encoding is iso8859-15.
>> Any hints?
>> 
>> best Tilmann
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html and provide commented,
>> minimal, self-contained, reproducible code.
> 
> 
> -- 
>  Olivier Crouzet, PhD
>  Laboratoire de Linguistique de Nantes -- UMR6310
>  CNRS / Université de Nantes
>  Chemin de la Censive du Tertre -- BP 81227
>  44312 Nantes cedex 3
>  France
> 
>  http://www.lling.univ-nantes.fr/
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list