Learn R Programming

rle (version 0.9.2)

Extract.rle: Indexing Methods for rle Objects

Description

These methods are defined and produce an error (except for character input) to future-proof code that depends on the rle package by preventing their use.

Usage

# S3 method for rle
[(x, i, ...)

# S3 method for rle [(x, i, ...) <- value

# S3 method for rle [[(x, i, ...)

# S3 method for rle [[(x, i, ...) <- value

# S3 method for rle $(x, name)

# S3 method for rle $(x, name) <- value

Arguments

x, i, name, value, ...

Arguments to indexing operators. See Extract documentation in the base package.

Value

At this time, all functions raise an error except for character indices. This behaviour can be overridden by setting options(rle.unclass_index=TRUE), which effectively unclasses the objects before indexing.

Details

At this time, the rle package does not support indexing operations by logical or numeric indices, but it is likely to do so in the future. Therefore, we reserve the syntax now to prevent users of this package from relying on the default behaviour of the indexing operators.

Examples

Run this code
# NOT RUN {
# Indexing by character or by $ works, including sub-indexing.
x <- rle(1:5)
x[["values"]] <- 2:6
x
x$values[2:3] <- 7:8
x


# }
# NOT RUN {
# Numerical indexing doesn't, unless `options(rle.unclass_index=TRUE)` is set.
x[1]
x[[1]]
# }

Run the code above in your browser using DataLab