mteb/BrightProStackoverflowRetrieval huggingface dataset:
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  Sys.getenv: Get Environment Variables

##  Description

` Sys.getenv ` obtains the values of the environment variables.

##  Usage

    
    
    Sys.getenv(x = NULL, unset = "", names = NA)

##  Arguments

x

a character vector, or ` NULL ` .

unset

a character string.

names

logical: should the result be named? If ` NA ` (the default) single-element
results are not named whereas multi-element results are.

##  Value

A vector of the same length as ` x ` , with (if ` names == TRUE ` ) the
variable names as its ` names ` attribute. Each element holds the value of the
environment variable named by the corresponding component of ` x ` (or the
value of ` unset ` if no environment variable with that name was found).

On most platforms ` Sys.getenv() ` will return a named vector giving the
values of all the environment variables, sorted in the current locale. It may
be confused by names containing ` = ` which some platforms allow but POSIX
does not. (Windows is such a platform: there names including ` = ` are
truncated just before the first ` = ` .)

When ` x ` is missing and ` names ` is not false, the result is of class `
"Dlist" ` in order to get a nice ` [ print
](/link/print?package=base&version=3.6.2) ` method.

##  Details

Both arguments will be coerced to character if necessary.

Setting ` unset = NA ` will enable unset variables and those set to the value
` "" ` to be distinguished, _if the OS does_ . POSIX requires the OS to
distinguish, and all known current  R  platforms do.

##  See Also

` [ Sys.setenv ](/link/Sys.setenv?package=base&version=3.6.2) ` , ` [
Sys.getlocale ](/link/Sys.getlocale?package=base&version=3.6.2) ` for the
locale in use, ` [ getwd ](/link/getwd?package=base&version=3.6.2) ` for the
working directory.

The help for ‘ [ environment variables
](/link/environment%20variables?package=base&version=3.6.2) ’ lists many of
the environment variables used by  R  .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FSys.getenv&utm_source=r-docs&utm_medium=docs&utm_term=Sys.getenv&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    ## whether HOST is set will be shell-dependent e.g. Solaris' csh does not.
    Sys.getenv(c("R_HOME", "R_PAPERSIZE", "R_PRINTCMD", "HOST"))
    
    names(s <- Sys.getenv()) # all settings (the values could be very long)
    head(s, 12)# using the Dlist print() method
    
    ## Language and Locale settings -- but rather use Sys.getlocale()
    s[grep("^L(C|ANG)", names(s))]
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2FSys.getenv&utm_source=r-docs&utm_medium=docs&utm_term=Sys.getenv&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  charmatch: Partial String Matching

##  Description

` charmatch ` seeks matches for the elements of its first argument among those
of its second.

##  Usage

    
    
    charmatch(x, table, nomatch = NA_integer_)

##  Arguments

x

the values to be matched: converted to a character vector by ` [ as.character
](/link/as.character?package=base&version=3.6.2) ` . [ Long vectors
](/link/Long%20vectors?package=base&version=3.6.2) are supported.

table

the values to be matched against: converted to a character vector. [ Long
vectors ](/link/Long%20vectors?package=base&version=3.6.2) are not supported.

nomatch

the (integer) value to be returned at non-matching positions.

##  Value

An integer vector of the same length as ` x ` , giving the indices of the
elements in ` table ` which matched, or ` nomatch ` .

##  Details

Exact matches are preferred to partial matches (those where the value to be
matched has an exact match to the initial part of the target, but the target
is longer).

If there is a single exact match or no exact match and a unique partial match
then the index of the matching value is returned; if multiple exact or
multiple partial matches are found then ` 0 ` is returned and if no match is
found then ` nomatch ` is returned.

` NA ` values are treated as the string constant ` "NA" ` .

##  See Also

` [ pmatch ](/link/pmatch?package=base&version=3.6.2) ` , ` [ match
](/link/match?package=base&version=3.6.2) ` .

` [ startsWith ](/link/startsWith?package=base&version=3.6.2) ` for another
matching of initial parts of strings; ` [ grep
](/link/grep?package=base&version=3.6.2) ` or ` [ regexpr
](/link/regexpr?package=base&version=3.6.2) ` for more general (regexp)
matching of strings.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fcharmatch&utm_source=r-docs&utm_medium=docs&utm_term=charmatch&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    charmatch("", "")                             # returns 1
    charmatch("m",   c("mean", "median", "mode")) # returns 0
    charmatch("med", c("mean", "median", "mode")) # returns 2
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fcharmatch&utm_source=r-docs&utm_medium=docs&utm_term=charmatch&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  lower.tri: Lower and Upper Triangular Part of a Matrix

##  Description

Returns a matrix of logicals the same size of a given matrix with entries `
TRUE ` in the lower or upper triangle.

##  Usage

    
    
    lower.tri(x, diag = FALSE)
    upper.tri(x, diag = FALSE)

##  Arguments

x

a matrix or other  R  object with ` length(dim(x)) == 2 ` . For back
compatibility reasons, when the above is not fulfilled, ` [ as.matrix
](/link/as.matrix?package=base&version=3.6.2) (x) ` is called first.

diag

logical. Should the diagonal be included?

##  See Also

` [ diag ](/link/diag?package=base&version=3.6.2) ` , ` [ matrix
](/link/matrix?package=base&version=3.6.2) ` ; further ` [ row
](/link/row?package=base&version=3.6.2) ` and ` [ col
](/link/col?package=base&version=3.6.2) ` on which ` lower.tri() ` and `
upper.tri() ` are built.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Flower.tri&utm_source=r-docs&utm_medium=docs&utm_term=lower.tri&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    (m2 <- matrix(1:20, 4, 5))
    lower.tri(m2)
    m2[lower.tri(m2)] <- NA
    m2
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Flower.tri&utm_source=r-docs&utm_medium=docs&utm_term=lower.tri&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
s to mode ` "qr" ` . Objects either are QR
decompositions or they are not.

The LINPACK interface is restricted to matrices ` x ` with less than
\\(2^{31}\\) elements.

` qr.fitted ` and ` qr.resid ` only support the LINPACK interface.

Unsuccessful results from the underlying LAPACK code will result in an error
giving a positive error code: these can only be interpreted by detailed study
of the FORTRAN code.

##  References

Anderson. E. and ten others (1999) _LAPACK Users' Guide_ . Third Edition.
SIAM. Available on-line at [ http://www.netlib.org/lapack/lug/lapack_lug.html
](http://www.netlib.org/lapack/lug/lapack_lug.html) .

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

Dongarra, J. J., Bunch, J. R., Moler, C. B. and Stewart, G. W. (1978) _LINPACK
Users Guide._ Philadelphia: SIAM Publications.

##  See Also

` [ qr.Q ](/link/qr.Q?package=base&version=3.6.2) ` , ` [ qr.R
](/link/qr.R?package=base&version=3.6.2) ` , ` [ qr.X
](/link/qr.X?package=base&version=3.6.2) ` for reconstruction of the matrices.
` [ lm.fit ](/link/lm.fit?package=base&version=3.6.2) ` , ` [ lsfit
](/link/lsfit?package=base&version=3.6.2) ` , ` [ eigen
](/link/eigen?package=base&version=3.6.2) ` , ` [ svd
](/link/svd?package=base&version=3.6.2) ` .

` [ det ](/link/det?package=base&version=3.6.2) ` (using ` qr ` ) to compute
the determinant of a matrix.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fqr&utm_source=r-docs&utm_medium=docs&utm_term=qr&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
    h9 <- hilbert(9); h9
    qr(h9)$rank           #--> only 7
    qrh9 <- qr(h9, tol = 1e-10)
    qrh9$rank             #--> 9
    ##-- Solve linear equation system  H %*% x = y :
    y <- 1:9/10
    x <- qr.solve(h9, y, tol = 1e-10) # or equivalently :
    x <- qr.coef(qrh9, y) #-- is == but much better than
                          #-- solve(h9) %*% y
    h9 %*% x              # = y
    
    
    ## overdetermined system
    A <- matrix(runif(12), 4)
    b <- 1:4
    qr.solve(A, b) # or solve(qr(A), b)
    solve(qr(A, LAPACK = TRUE), b)
    # this is a least-squares solution, cf. lm(b ~ 0 + A)
    
    ## underdetermined system
    A <- matrix(runif(12), 3)
    b <- 1:3
    qr.solve(A, b)
    solve(qr(A, LAPACK = TRUE), b)
    # solutions will have one zero, not necessarily the same one
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fqr&utm_source=r-docs&utm_medium=docs&utm_term=qr&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  is.recursive: Is an Object Atomic or Recursive?

##  Description

` is.atomic ` returns ` TRUE ` if ` x ` is of an atomic type (or ` NULL ` )
and ` FALSE ` otherwise.

` is.recursive ` returns ` TRUE ` if ` x ` has a recursive (list-like)
structure and ` FALSE ` otherwise.

##  Usage

    
    
    is.atomic(x)
    is.recursive(x)

##  Arguments

x

object to be tested.

##  Details

` is.atomic ` is true for the [ atomic
](/link/atomic?package=base&version=3.6.2) types ( ` "logical" ` , ` "integer"
` , ` "numeric" ` , ` "complex" ` , ` "character" ` and ` "raw" ` ) and ` NULL
` .

Most types of objects are regarded as recursive. Exceptions are the atomic
types, ` NULL ` , symbols (as given by ` [ as.name
](/link/as.name?package=base&version=3.6.2) ` ), ` S4 ` objects with slots,
external pointers, and---rarely visible from  R  \---weak references and byte
code, see ` [ typeof ](/link/typeof?package=base&version=3.6.2) ` .

It is common to call the atomic types ‘atomic vectors’, but note that ` [
is.vector ](/link/is.vector?package=base&version=3.6.2) ` imposes further
restrictions: an object can be atomic but not a vector (in that sense).

These are [ primitive ](/link/primitive?package=base&version=3.6.2) functions.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ is.list ](/link/is.list?package=base&version=3.6.2) ` , ` [ is.language
](/link/is.language?package=base&version=3.6.2) ` , etc, and the `
demo("is.things") ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fis.recursive&utm_source=r-docs&utm_medium=docs&utm_term=is.recursive&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    require(stats)
    
    is.a.r <- function(x) c(is.atomic(x), is.recursive(x))
    
    is.a.r(c(a = 1, b = 3)) # TRUE FALSE
    is.a.r(list())          # FALSE TRUE - a list is a list
    is.a.r(list(2))         # FALSE TRUE
    is.a.r(lm)              # FALSE TRUE
    is.a.r(y ~ x)           # FALSE TRUE
    is.a.r(expression(x+1)) # FALSE TRUE
    is.a.r(quote(exp))      # FALSE FALSE
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fis.recursive&utm_source=r-docs&utm_medium=docs&utm_term=is.recursive&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
Quantifiers  regexp  |  matches  |  example  |  example output   
(highlighted characters are in <>)  
---|---|---|---  
` a? ` |  zero or one  |  ` quant("a?") ` | 
    
    
    <>.<a><>.<a><a><>.<a><a><a><>  
  
` a* ` |  zero or more  |  ` quant("a*") ` | 
    
    
    <>.<a><>.<aa><>.<aaa><>  
  
` a+ ` |  one or more  |  ` quant("a+") ` | 
    
    
    .<a>.<aa>.<aaa>  
  
` a{n} ` |  exactly ` n ` |  ` quant("a{2}") ` | 
    
    
    .a.<aa>.<aa>a  
  
` a{n, } ` |  ` n ` or more  |  ` quant("a{2,}") ` | 
    
    
    .a.<aa>.<aaa>  
  
` a{n, m} ` |  between ` n ` and ` m ` |  ` quant("a{2,4}") ` | 
    
    
    .a.<aa>.<aaa>  
  
###  Groups

` ref <- function(rx) str_view("abbaab", rx) `
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  make.names: Make Syntactically Valid Names

##  Description

Make syntactically valid names out of character vectors.

##  Usage

    
    
    make.names(names, unique = FALSE, allow_ = TRUE)

##  Arguments

names

character vector to be coerced to syntactically valid names. This is coerced
to character if necessary.

unique

logical; if ` TRUE ` , the resulting elements are unique. This may be desired
for, e.g., column names.

allow_

logical. For compatibility with  R  prior to 1.9.0.

##  Value

A character vector of same length as ` names ` with each changed to a
syntactically valid name, in the current locale's encoding.

##  Warning

Some OSes, notably FreeBSD, report extremely incorrect information about which
characters are alphabetic in some locales (typically, all multi-byte locales
including UTF-8 locales). However,  R  provides substitutes on Windows, macOS
and AIX.

##  Details

A syntactically valid name consists of letters, numbers and the dot or
underline characters and starts with a letter or the dot not followed by a
number. Names such as ` ".2way" ` are not valid, and neither are the [
reserved ](/link/reserved?package=base&version=3.6.2) words.

The definition of a _letter_ depends on the current locale, but only ASCII
digits are considered to be digits.

The character ` "X" ` is prepended if necessary. All invalid characters are
translated to ` "." ` . A missing value is translated to ` "NA" ` . Names
which match  R  keywords have a dot appended to them. Duplicated values are
altered by ` [ make.unique ](/link/make.unique?package=base&version=3.6.2) ` .

##  See Also

` [ make.unique ](/link/make.unique?package=base&version=3.6.2) ` , ` [ names
](/link/names?package=base&version=3.6.2) ` , ` [ character
](/link/character?package=base&version=3.6.2) ` , ` [ data.frame
](/link/data.frame?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fmake.names&utm_source=r-docs&utm_medium=docs&utm_term=make.names&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    make.names(c("a and b", "a-and-b"), unique = TRUE)
    # "a.and.b"  "a.and.b.1"
    make.names(c("a and b", "a_and_b"), unique = TRUE)
    # "a.and.b"  "a_and_b"
    make.names(c("a and b", "a_and_b"), unique = TRUE, allow_ = FALSE)
    # "a.and.b"  "a.and.b.1"
    make.names(c("", "X"), unique = TRUE)
    # "X.1" "X" currently; R up to 3.0.2 gave "X" "X.1"
    
    state.name[make.names(state.name) != state.name] # those 10 with a space
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fmake.names&utm_source=r-docs&utm_medium=docs&utm_term=make.names&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  dim: Dimensions of an Object

##  Description

Retrieve or set the dimension of an object.

##  Usage

    
    
    dim(x)
    dim(x) <- value

##  Arguments

x

an  R  object, for example a matrix, array or data frame.

value

For the default method, either ` NULL ` or a numeric vector, which is coerced
to integer (by truncation).

##  Value

For an array (and hence in particular, for a matrix) ` dim ` retrieves the `
dim ` attribute of the object. It is ` NULL ` or a vector of mode ` [ integer
](/link/integer?package=base&version=3.6.2) ` .

The replacement method changes the ` "dim" ` attribute (provided the new value
is compatible) and removes any ` "dimnames" ` _and_ ` "names" ` attributes.

##  Details

The functions ` dim ` and ` dim<- ` are [ internal generic
](/link/internal%20generic?package=base&version=3.6.2) [ primitive
](/link/primitive?package=base&version=3.6.2) functions.

` dim ` has a method for ` [ data.frame
](/link/data.frame?package=base&version=3.6.2) ` s, which returns the lengths
of the ` row.names ` attribute of ` x ` and of ` x ` (as the numbers of rows
and columns respectively).

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ ncol ](/link/ncol?package=base&version=3.6.2) ` , ` [ nrow
](/link/nrow?package=base&version=3.6.2) ` and ` [ dimnames
](/link/dimnames?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fdim&utm_source=r-docs&utm_medium=docs&utm_term=dim&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    x <- 1:12 ; dim(x) <- c(3,4)
    x
    
    # simple versions of nrow and ncol could be defined as follows
    nrow0 <- function(x) dim(x)[1]
    ncol0 <- function(x) dim(x)[2]
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fdim&utm_source=r-docs&utm_medium=docs&utm_term=dim&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  lengths: Lengths of List or Vector Elements

##  Description

Get the length of each element of a ` [ list
](/link/list?package=base&version=3.6.2) ` or atomic vector ( ` [ is.atomic
](/link/is.atomic?package=base&version=3.6.2) ` ) as an integer or numeric
vector.

##  Usage

    
    
    lengths(x, use.names = TRUE)

##  Arguments

x

a ` [ list ](/link/list?package=base&version=3.6.2) ` , list-like such as an `
[ expression ](/link/expression?package=base&version=3.6.2) ` or an atomic
vector (for which the result is trivial).

use.names

logical indicating if the result should inherit the ` [ names
](/link/names?package=base&version=3.6.2) ` from ` x ` .

##  Value

A non-negative ` [ integer ](/link/integer?package=base&version=3.6.2) ` of
length ` length(x) ` , except when any element has a length of more than
\\(2^{31}-1\\) elements, when it returns a double vector. When ` use.names `
is true, the names are taken from the names on ` x ` , if any.

##  Details

This function loops over ` x ` and returns a compatible vector containing the
length of each element in ` x ` . Effectively, ` length(x[[i]]) ` is called
for all ` i ` , so any methods on ` length ` are considered.

##  See Also

` [ length ](/link/length?package=base&version=3.6.2) ` for getting the length
of any  R  object.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Flengths&utm_source=r-docs&utm_medium=docs&utm_term=lengths&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    require(stats)
    ## summarize by month
    l <- split(airquality$Ozone, airquality$Month)
    avgOz <- lapply(l, mean, na.rm=TRUE)
    ## merge result
    airquality$avgOz <- rep(unlist(avgOz, use.names=FALSE), lengths(l))
    ## but this is safer and cleaner, but can be slower
    airquality$avgOz <- unsplit(avgOz, airquality$Month)
    
    ## should always be true, except when a length does not fit in 32 bits
    stopifnot(identical(lengths(l), vapply(l, length, integer(1L))))
    
    ## empty lists are not a problem
    x <- list()
    stopifnot(identical(lengths(x), integer()))
    
    ## nor are "list-like" expressions:
    lengths(expression(u, v, 1+ 0:9))
    
    ## and we should dispatch to length methods
    f <- c(rep(1, 3), rep(2, 6), 3)
    dates <- split(as.POSIXlt(Sys.time() + 1:10), f)
    stopifnot(identical(lengths(dates), vapply(dates, length, integer(1L))))
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Flengths&utm_source=r-docs&utm_medium=docs&utm_term=lengths&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)
A character class containing a single character is a nice alternative to
backslash escapes when you want to include a single metacharacter in a regex.
Many people find this more readable.

    
    
    # Look for a literal character that normally has special meaning in a regex
    str_view(c("abc", "a.c", "a*c", "a c"), "a[.]c")
    #> [2] │ <a.c>
    str_view(c("abc", "a.c", "a*c", "a c"), ".[*]c")
    #> [3] │ <a*c>
    str_view(c("abc", "a.c", "a*c", "a c"), "a[ ]")
    #> [4] │ <a >c