# R: Read or Set the Declared Encodings for a Character Vector

Encoding {base} | R Documentation

## Read or Set the Declared Encodings for a Character Vector

### Description

Read or set the declared encodings for a character vector.

### Usage

    Encoding(x)

    Encoding(x) <- value

### Arguments

`x` | A character vector.
`value` | A character vector of positive length.

### Details

Character strings in R can be declared to be in `"latin1"` or `"UTF-8"`. These declarations can be read by `Encoding`, which will return a character vector of values `"latin1"`, `"UTF-8"` or `"unknown"`, or set, when `value` is recycled as needed and other values are silently treated as `"unknown"`.

There are other ways for character strings to acquire a declared encoding apart from explicitly setting it. Functions `scan`, `read.table`, `readLines`, `parse` and `source` have an `encoding` argument that is used to declare encodings, `iconv` declares encodings from its `from` argument, and console input in suitable locales is also declared.

### Value

A character vector.

### Examples

    ## x is intended to be in latin1
    x <- "fa\xE7ile"
    Encoding(x)
    Encoding(x) <- "latin1"
    x
    xx <- iconv(x, "latin1", "UTF-8")
    Encoding(c(x, xx))
    c(x, xx)

[Package base version 2.6.0 Index]