The R Project SVN R

Rev

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

Rev Author Line No. Line
42333 ripley 1
% File src/library/base/man/encodeString.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 1995-2008 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
32237 ripley 6
\name{encodeString}
56186 murdoch 7
\alias{encodeString}
32245 ripley 8
\title{
9
  Encode Character Vector as for Printing
10
}
32237 ripley 11
\description{
12
  \code{encodeString} escapes the strings in a character vector in the
13
  same way \code{print.default} does, and optionally fits the encoded
32245 ripley 14
  strings within a field width.
32237 ripley 15
}
16
\usage{
35281 ripley 17
encodeString(x, width = 0, quote = "", na.encode = TRUE,
18
             justify = c("left", "right", "centre", "none"))
32237 ripley 19
}
20
\arguments{
32240 ripley 21
  \item{x}{A character vector, or an object that can be coerced to one
22
    by \code{\link{as.character}}.}
35281 ripley 23
  \item{width}{integer: the minimum field width.  If \code{NULL} or
24
    \code{NA}, this is taken to be the largest field width needed for
25
    any element of \code{x}.}
32237 ripley 26
  \item{quote}{character: quoting character, if any.}
35281 ripley 27
  \item{na.encode}{logical: should \code{NA} strings be encoded?}
32245 ripley 28
  \item{justify}{character: partial matches are allowed.  If padding to
35281 ripley 29
    the minimum field width is needed, how should spaces be inserted?
30
    \code{justify == "none"} is equivalent to \code{width = 0}, for
31
    consistency with \code{format.default}.}
32237 ripley 32
}
33
\details{
46956 ripley 34
  This escapes backslash and the control characters \samp{\\a} (bell),
35
  \samp{\\b} (backspace), \samp{\\f} (formfeed), \samp{\\n} (line feed),
50567 ripley 36
  \samp{\\r} (carriage return), \samp{\\t} (tab) and \samp{\\v}
37
  (vertical tab) as well as any non-printable characters in a
38
  single-byte locale, which are printed in octal notation (\samp{\\xyz}
39
  with leading zeroes).
40
 
41
  Which characters are non-printable depends on the current locale.
42
  Windows' reporting of printable characters is unreliable, so there all
32245 ripley 43
  other control characters are regarded as non-printable, and all
50567 ripley 44
  characters with codes 32--255 as printable in a single-byte locale.
35281 ripley 45
  See \code{\link{print.default}} for how non-printable characters are
46
  handled in multi-byte locales.
32237 ripley 47
 
48
  If \code{quote} is a single or double quote any embedded quote of the
32245 ripley 49
  same type is escaped.  Note that justification is of the quoted
50
  string, hence spaces are added outside the quotes.
32237 ripley 51
}
35281 ripley 52
\note{
53
  The default for \code{width} is different from \code{format.default},
38402 ripley 54
  which does similar things for character vectors but without encoding
55
  using escapes.
35281 ripley 56
}
32237 ripley 57
\value{
32245 ripley 58
  A character vector of the same length as \code{x}, with the same
35297 ripley 59
  attributes (including names and dimensions) but with no class set.
61240 ripley 60
 
61282 ripley 61
  As from \R 3.0.0, marked UTF-8 encodings are preserved.
32237 ripley 62
}
63
\seealso{
64
  \code{\link{print.default}}
65
}
66
\examples{
67
x <- "ab\bc\ndef"
68
print(x)
69
cat(x) # interprets escapes
61150 ripley 70
cat(encodeString(x), "\n", sep = "") # similar to print()
32237 ripley 71
 
72
factor(x) # makes use of this to print the levels
32245 ripley 73
 
74
x <- c("a", "ab", "abcde")
41593 ripley 75
encodeString(x, width = NA) # left justification
76
encodeString(x, width = NA, justify = "c")
77
encodeString(x, width = NA, justify = "r")
78
encodeString(x, width = NA, quote = "'", justify = "r")
32237 ripley 79
}
80
\keyword{ utilities }
81