-
Notifications
You must be signed in to change notification settings - Fork 306
/
encodeString.Rd
82 lines (77 loc) · 2.94 KB
/
encodeString.Rd
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
75
76
77
78
79
80
81
% File src/library/base/man/encodeString.Rd
% Part of the R package, http://www.R-project.org
% Copyright 1995-2008 R Core Development Team
% Distributed under GPL 2 or later
\name{encodeString}
\alias{encodeString}
\title{
Encode Character Vector as for Printing
}
\description{
\code{encodeString} escapes the strings in a character vector in the
same way \code{print.default} does, and optionally fits the encoded
strings within a field width.
}
\usage{
encodeString(x, width = 0, quote = "", na.encode = TRUE,
justify = c("left", "right", "centre", "none"))
}
\arguments{
\item{x}{A character vector, or an object that can be coerced to one
by \code{\link{as.character}}.}
\item{width}{integer: the minimum field width. If \code{NULL} or
\code{NA}, this is taken to be the largest field width needed for
any element of \code{x}.}
\item{quote}{character: quoting character, if any.}
\item{na.encode}{logical: should \code{NA} strings be encoded?}
\item{justify}{character: partial matches are allowed. If padding to
the minimum field width is needed, how should spaces be inserted?
\code{justify == "none"} is equivalent to \code{width = 0}, for
consistency with \code{format.default}.}
}
\details{
This escapes backslash and the control characters \code{\a} (bell),
\code{\b} (backspace), \code{\f} (formfeed), \code{\n} (line feed),
\code{\r} (carriage return), \code{\t} (tab) and \code{\v} (vertical tab)
as well as any non-printable characters in a
single-byte locale, which are printed in octal notation
(\code{\xyz} with leading zeroes).
#ifdef unix
(Which characters are non-printable depends on the current locale.)
#endif
#ifdef windows
(Windows' reporting of printable characters is unreliable, so all
other control characters are regarded as non-printable, and all
characters with codes 32--255 as printable in a single-byte locale.)
#endif
See \code{\link{print.default}} for how non-printable characters are
handled in multi-byte locales.
If \code{quote} is a single or double quote any embedded quote of the
same type is escaped. Note that justification is of the quoted
string, hence spaces are added outside the quotes.
}
\note{
The default for \code{width} is different from \code{format.default},
which does similar things for character vectors but without encoding
using escapes.
}
\value{
A character vector of the same length as \code{x}, with the same
attributes (including names and dimensions) but with no class set.
}
\seealso{
\code{\link{print.default}}
}
\examples{
x <- "ab\bc\ndef"
print(x)
cat(x) # interprets escapes
cat(encodeString(x), "\n", sep="") # similar to print()
factor(x) # makes use of this to print the levels
x <- c("a", "ab", "abcde")
encodeString(x, width = NA) # left justification
encodeString(x, width = NA, justify = "c")
encodeString(x, width = NA, justify = "r")
encodeString(x, width = NA, quote = "'", justify = "r")
}
\keyword{ utilities }