disord | R Documentation |
disord
objectsAllows 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.
is.disord(x)
hash(x)
hashcal(x,ultra_strict=FALSE)
disord(v,h,drop=TRUE)
elements(x)
x |
Object of class |
v |
Vector of coefficients |
h |
Hash code |
drop |
Boolean, with default |
ultra_strict |
Boolean, with default |
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.
Boolean, hash code, or object of class disord
as
appropriate.
Robin K. S. Hankin
(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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.