The R Project SVN R

Rev

Rev 32241 | Rev 35297 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
32237 ripley 1
\name{encodeString}
2
\alias{encodeString}
32245 ripley 3
\title{
4
  Encode Character Vector as for Printing
5
}
32237 ripley 6
\description{
7
  \code{encodeString} escapes the strings in a character vector in the
8
  same way \code{print.default} does, and optionally fits the encoded
32245 ripley 9
  strings within a field width.
32237 ripley 10
}
11
\usage{
32245 ripley 12
encodeString(x, w = 0, quote = "", na = TRUE,
13
             justify = c("left", "right", "centre"))
32237 ripley 14
}
15
\arguments{
32240 ripley 16
  \item{x}{A character vector, or an object that can be coerced to one
17
    by \code{\link{as.character}}.}
32245 ripley 18
  \item{w}{integer: the minimum field width.  If \code{NA}, this is
19
    taken to be the largest field width needed for any element of \code{x}.}
32237 ripley 20
  \item{quote}{character: quoting character, if any.}
21
  \item{na}{logical: should \code{NA} strings be encoded?}
32245 ripley 22
  \item{justify}{character: partial matches are allowed.  If padding to
23
    the minimum field width is needed, how should spaces be inserted?}
32237 ripley 24
}
25
\details{
32245 ripley 26
  This escapes backslash and the control characters \code{\a} (bell),
27
  \code{\b} (backspace), \code{\f} (formfeed), \code{\n} (line feed),
28
  \code{\r} (carriage return), \code{\t} (tab), \code{\v} (vertical tab)
29
  and \code{\0} (nul) as well as any non-printable characters, which are
30
  printed in octal notation (\code{\xyz} with leading zeroes).
32237 ripley 31
#ifdef unix
32
  (Which characters are non-printable depends on the current locale.)
33
#endif
34
#ifdef windows
32245 ripley 35
  (Windows' reporting of printable characters is unreliable, so all
36
  other control characters are regarded as non-printable, and all
37
  characters with codes 32--255 as printable.)
32237 ripley 38
#endif
39
 
40
  If \code{quote} is a single or double quote any embedded quote of the
32245 ripley 41
  same type is escaped.  Note that justification is of the quoted
42
  string, hence spaces are added outside the quotes.
32237 ripley 43
}
44
\value{
32245 ripley 45
  A character vector of the same length as \code{x}, with the same
46
  attributes (including names and dimensions).
32237 ripley 47
}
48
\seealso{
49
  \code{\link{print.default}}
50
}
51
\examples{
52
x <- "ab\bc\ndef"
53
print(x)
54
cat(x) # interprets escapes
55
cat(encodeString(x), "\n", sep="") # similar to print()
56
 
57
factor(x) # makes use of this to print the levels
32245 ripley 58
 
59
x <- c("a", "ab", "abcde")
60
encodeString(x, w = NA) # left justification
61
encodeString(x, w = NA, justify = "c")
62
encodeString(x, w = NA, justify = "r")
63
encodeString(x, w = NA, quote = "'", justify = "r")
32237 ripley 64
}
65
\keyword{ utilities }
66