Functionality for disord objects
disord.RdAllows 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.
Arguments
- x
Object of class
disord- v
Vector of coefficients
- h
Hash code
- drop
Boolean, with default
FALSEmeaning to return a disord object andTRUEmeaning to calldrop()before returning- ultra_strict
Boolean, with default
FALSEmeaning to use justxto generate the hash, andTRUEmeaning to use the date and a random number as well [this ensures that the hash is generated only once]
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
(a <- rdis())
#> A disord object with hash 158099d7e3c57c187a7e0542dbb2302574b881ad and elements
#> [1] 2 5 8 1 3 3 2 7 3
#> (in some order)
(b <- rdis())
#> A disord object with hash c6dde1f0385dc3b872cfd87e6c13268833fc3025 and elements
#> [1] 4 1 7 6 6 3 9 2 8
#> (in some order)
a + 2*a + 2^a # fine
#> A disord object with hash 158099d7e3c57c187a7e0542dbb2302574b881ad and elements
#> [1] 10 47 280 5 17 17 10 149 17
#> (in some order)
# a + b # this would give an error if executed
a[a<0.5] <- 0 # round down; replacement works as expected
elements(a)
#> [1] 2 5 8 1 3 3 2 7 3