ranged: A S3 class for caching the range of a vector

Description Usage Arguments Performance Examples

View source: R/ranged.r

Description

This class is designed for dealing with large vectors, where the cost of recomputing the range multiple times is prohibitive. It provides methods for print and str that display only the range, not the contents.

Usage

1

Arguments

x

a numeric vector

range

the range of the vector (excluding missing values), if known. If unknown, it will be computed with frange, a fast C++ implementation of range.

Performance

For best performance, you may want to run copy and paste the contents of this function into your function, to avoid making any copies of x. This is probably only necessary if you're dealing with extremely large vectors, > 100 million obs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- runif(1e6)
y <- ranged(x)
range(y)
y
str(y)

# Modifications to the class currently destroy the cache
y[1] <- 10
max(y)
class(y)
z <- y + 10
max(z)
class(z)

hadley/bigvis documentation built on May 17, 2019, 9:45 a.m.