Rev 50567 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% 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 thesame way \code{print.default} does, and optionally fits the encodedstrings 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 oneby \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 forany 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 tothe minimum field width is needed, how should spaces be inserted?\code{justify == "none"} is equivalent to \code{width = 0}, forconsistency with \code{format.default}.}}\details{This escapes backslash and the control characters \samp{\\a} (bell),\samp{\\b} (backspace), \samp{\\f} (formfeed), \samp{\\n} (line feed),\samp{\\r} (carriage return), \samp{\\t} (tab) and \samp{\\v}(vertical tab) as well as any non-printable characters in asingle-byte locale, which are printed in octal notation (\samp{\\xyz}with leading zeroes).Which characters are non-printable depends on the current locale.Windows' reporting of printable characters is unreliable, so there allother control characters are regarded as non-printable, and allcharacters with codes 32--255 as printable in a single-byte locale.See \code{\link{print.default}} for how non-printable characters arehandled in multi-byte locales.If \code{quote} is a single or double quote any embedded quote of thesame type is escaped. Note that justification is of the quotedstring, 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 encodingusing escapes.}\value{A character vector of the same length as \code{x}, with the sameattributes (including names and dimensions) but with no class set.}\seealso{\code{\link{print.default}}}\examples{x <- "ab\bc\ndef"print(x)cat(x) # interprets escapescat(encodeString(x), "\n", sep="") # similar to print()factor(x) # makes use of this to print the levelsx <- c("a", "ab", "abcde")encodeString(x, width = NA) # left justificationencodeString(x, width = NA, justify = "c")encodeString(x, width = NA, justify = "r")encodeString(x, width = NA, quote = "'", justify = "r")}\keyword{ utilities }