Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

vec_proxy_compare

Comparison and order proxy


Description

vec_proxy_compare() and vec_proxy_order() return proxy objects, i.e. an atomic vector or data frame of atomic vectors.

For vctrs_vctr objects:

  • vec_proxy_compare() determines the behavior of <, >, >= and <= (via vec_compare()); and min(), max(), median(), and quantile().

  • vec_proxy_order() determines the behavior of order() and sort() (via xtfrm()).

Usage

vec_proxy_compare(x, ...)

vec_proxy_order(x, ...)

Arguments

x

A vector x.

...

These dots are for future extensions and must be empty.

Details

The default method of vec_proxy_compare() assumes that all classes built on top of atomic vectors or records are comparable. Internally the default calls vec_proxy_equal(). If your class is not comparable, you will need to provide a vec_proxy_compare() method that throws an error.

The behavior of vec_proxy_order() is identical to vec_proxy_compare(), with the exception of lists. Lists are not comparable, as comparing elements of different types is undefined. However, to allow ordering of data frames containing list-columns, the ordering proxy of a list is generated as an integer vector that can be used to order list elements by first appearance.

Value

A 1d atomic vector or a data frame.

Dependencies

Examples

# Lists are not comparable
x <- list(1:2, 1, 1:2, 3)
try(vec_compare(x, x))

# But lists are orderable by first appearance to allow for
# ordering data frames with list-cols
df <- new_data_frame(list(x = x))
vec_sort(df)

vctrs

Vector Helpers

v0.3.8
MIT + file LICENSE
Authors
Hadley Wickham [aut], Lionel Henry [aut, cre], Davis Vaughan [aut], data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.