Rev 85981 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/charClass.Rd% Part of the R package, https://www.R-project.org% Copyright 2022 R Core Team% Distributed under GPL 2 or later\name{charClass}\alias{charClass}\title{Character Classification}\description{An interface to the (C99) wide character classification functions in use.}\usage{charClass(x, class)}\arguments{\item{x}{\strong{Either} a UTF-8-encoded length-1 character vector\strong{or} an integer vector of Unicode points (or a vectorcoercible to integer).}\item{class}{A character string, one of those given in the\sQuote{Details} section.}}\details{The classification into character classes is platform-dependent. Theclasses are determined by internal tables on Windows and (optionallybut by default) on macOS and \I{AIX}.The character classes are interpreted as follows:\describe{\item{\code{"alnum"}}{Alphabetic or numeric.}\item{\code{"alpha"}}{Alphabetic.}\item{\code{"blank"}}{Space or tab.}\item{\code{"cntrl"}}{Control characters.}\item{\code{"digit"}}{Digits \code{0-9}.}\item{\code{"graph"}}{Graphical characters (printable charactersexcept whitespace).}\item{\code{"lower"}}{Lower-case alphabetic.}\item{\code{"print"}}{Printable characters.}\item{\code{"punct"}}{Punctuation characters. Some platforms treat allnon-alphanumeric graphical characters as punctuation.}\item{\code{"space"}}{Whitespace, including tabs, form and linefeeds and carriage returns. Some OSes include non-breakingspaces, some exclude them.}\item{\code{"upper"}}{Upper-case alphabetic.}\item{\code{"xdigit"}}{Hexadecimal character, one of \code{0-9A-fa-f}.}}Alphabetic characters contain all lower- and upper-case ones and someothers (for example, those in \sQuote{title case}).Whether a character is printable is used to decide whether to escapeit when printing -- see the help for \code{\link{print.default}}.If \code{x} is a character string it should either be ASCII or declaredas UTF-8 -- see \code{\link{Encoding}}.\code{charClass} was added in \R 4.1.0. A less direct way to examinecharacter classes which also worked in earlier versions is to usesomething like \code{grepl("[[:print:]]", intToUtf8(x))} -- however,the regular-expression code might not use the same classificationfunctions as printing and on macOS used not to.}\value{A logical vector of the length the number of characters or integers in\code{x}.}\note{Non-ASCII digits are excluded by the C99 standard from the class\code{"digit"}: most platforms will have them as alphabetic.It is an assumption that the system's wide character classificationfunctions are coded in Unicode points, but this is known to be truefor all recent platforms.The classification may depend on the locale even on one platform.}\seealso{Character classes are used in \link{regular expression}s.The OS's \command{man} pages for \code{iswctype} and \code{wctype}.}\examples{x <- c(48:70, 32, 0xa0) # Last is non-breaking spacecl <- c("alnum", "alpha", "blank", "digit", "graph", "punct", "upper", "xdigit")X <- lapply(cl, function(y) charClass(x,y)); names(X) <- clX <- as.data.frame(X); row.names(X) <- sQuote(intToUtf8(x, multiple = TRUE))XcharClass("ABC123", "alpha")## Some accented capital Greek characters(x <- "\u0386\u0388\u0389")charClass(x, "upper")## How many printable characters are there? (Around 280,000 in Unicode 13.)## There are 2^21-1 possible Unicode points (most not yet assigned).pr <- charClass(1:0x1fffff, "print")table(pr)}