Learn R Programming

disordR (version 0.9-8.2)

disord: Functionality for disord objects

Description

Allows arithmetic operators to be used for disord objects; the canonical application is coefficients of multivariate polynomials (as in the mvp package). The issue is that the storage order of disord objects is implementation-specific but the order (whatever it is) must be consistent between the list of keys and values in an associative array.

Usage

is.disord(x)
hash(x)
hashcal(x,ultra_strict=FALSE)
disord(v,h,drop=TRUE)
elements(x)

Value

Boolean, hash code, or object of class disord as appropriate.

Arguments

x

Object of class disord

v

Vector of coefficients

h

Hash code

drop

Boolean, with default FALSE meaning to return a disord object and TRUE meaning to call drop() before returning

ultra_strict

Boolean, with default FALSE meaning to use just x to generate the hash, and TRUE meaning to use the date and a random number as well [this ensures that the hash is generated only once]

Author

Robin K. S. Hankin

Details

A detailed vignette is provided that motivates the package. In applications such as the mvp or clifford packages, the user will not need to even think about the disordR package: it works in the background. The purpose of the package is to trap plausible idiom that is ill-defined (implementation-specific) and return an informative error, rather than returning a possibly incorrect result.

The package provides a single S4 class, disord, which has two slots, .Data and hash.

Function disord() takes an R object such as a vector or list and returns a disord object, which is useful in the context of the STL map class.

Function hash() returns the hash of an object (compare hashcal() which is used to actually calculate the hash code).

The package detects acceptable and forbidden operations using hash codes: function consistent() checks for its arguments having the same hash code, and thus their elements can be paired up (e.g. added). Idiomatically, a %~% b is equivalent to consistent(a,b).

Function elements() takes a disord and returns a regular R object, typically a vector or a list.

Examples

Run this code

(a <- rdis())
(b <- rdis())

a + 2*a + 2^a  # fine
# a + b # this would give an error if executed

a[a<0.5] <- 0       # round down; replacement works as expected

elements(a)

Run the code above in your browser using DataLab