File: str_length.Rd

package info (click to toggle)
r-cran-stringr 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,032 kB
  • sloc: javascript: 11; sh: 9; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/length.R
\name{str_length}
\alias{str_length}
\alias{str_width}
\title{Compute the length/width}
\usage{
str_length(string)

str_width(string)
}
\arguments{
\item{string}{Input vector. Either a character vector, or something
coercible to one.}
}
\value{
A numeric vector the same length as \code{string}.
}
\description{
\code{str_length()} returns the number of codepoints in a string. These are
the individual elements (which are often, but not always letters) that
can be extracted with \code{\link[=str_sub]{str_sub()}}.

\code{str_width()} returns how much space the string will occupy when printed
in a fixed width font (i.e. when printed in the console).
}
\examples{
str_length(letters)
str_length(NA)
str_length(factor("abc"))
str_length(c("i", "like", "programming", NA))

# Some characters, like emoji and Chinese characters (hanzi), are square
# which means they take up the width of two Latin characters
x <- c("\u6c49\u5b57", "\U0001f60a")
str_view(x)
str_width(x)
str_length(x)

# There are two ways of representing a u with an umlaut
u <- c("\u00fc", "u\u0308")
# They have the same width
str_width(u)
# But a different length
str_length(u)
# Because the second element is made up of a u + an accent
str_sub(u, 1, 1)
}
\seealso{
\code{\link[stringi:stri_length]{stringi::stri_length()}} which this function wraps.
}