File: utf8_encode.Rd

package info (click to toggle)
r-cran-utf8 1.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,060 kB
  • sloc: ansic: 25,890; python: 1,616; sh: 13; makefile: 6
file content (74 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utf8_encode.R
\name{utf8_encode}
\alias{utf8_encode}
\title{Encode Character Object as for UTF-8 Printing}
\usage{
utf8_encode(
  x,
  ...,
  width = 0L,
  quote = FALSE,
  justify = "left",
  escapes = NULL,
  display = FALSE,
  utf8 = NULL
)
}
\arguments{
\item{x}{character object.}

\item{...}{These dots are for future extensions and must be empty.}

\item{width}{integer giving the minimum field width; specify \code{NULL} or
\code{NA} for no minimum.}

\item{quote}{logical scalar indicating whether to surround results with
double-quotes and escape internal double-quotes.}

\item{justify}{justification; one of \code{"left"}, \code{"right"},
\code{"centre"}, or \code{"none"}. Can be abbreviated.}

\item{escapes}{a character string specifying the display style for the
backslash escapes, as an ANSI SGR parameter string, or NULL for no styling.}

\item{display}{logical scalar indicating whether to optimize the encoding
for display, not byte-for-byte data transmission.}

\item{utf8}{logical scalar indicating whether to encode for a UTF-8 capable
display (ASCII-only otherwise), or \code{NULL} to encode for output
capabilities as determined by \code{output_utf8()}.}
}
\value{
A character object with the same attributes as \code{x} but with
\code{Encoding} set to \code{"UTF-8"}.
}
\description{
Escape the strings in a character object, optionally adding quotes or
spaces, adjusting the width for display.
}
\details{
\code{utf8_encode()} encodes a character object for printing on a UTF-8 device
by escaping controls characters and other non-printable characters. When
\code{display = TRUE}, the function optimizes the encoding for display by
removing default ignorable characters (soft hyphens, zero-width spaces,
etc.) and placing zero-width spaces after wide emoji. When
\code{output_utf8()} is \code{FALSE} the function escapes all non-ASCII
characters and gives the same results on all platforms.
}
\examples{

# the second element is encoded in latin-1, but declared as UTF-8
x <- c("fa\u00E7ile", "fa\xE7ile", "fa\xC3\xA7ile")
Encoding(x) <- c("UTF-8", "UTF-8", "bytes")

# encoding
utf8_encode(x)

# add style to the escapes
cat(utf8_encode("hello\nstyled\\\\world", escapes = "1"), "\n")

}
\seealso{
\code{\link[=utf8_print]{utf8_print()}}.
}