GithubHelp home page GithubHelp logo

disordr's Introduction

The disordR package

CRAN_Status_Badge

Overview

Ordinary R vectors are unsuitable for working with values of associative maps because elements of an R vector may be accessed by reference to their location in the vector, but associative maps are stored in arbitrary order. However, when associating keys with values one needs both parts to be in 1-1 correspondence, so one cannot dispense with the order entirely. The disordR package includes a single S4 class, disord. This class allows one to perform only those operations appropriate for manipulating values (or keys) of associative maps.

A useful heuristic is that one is only allowed to access or modify a disord object using a python list comprehension. The idea is to prevent “illegal” operations on values (or keys) of associative maps, whose order is undefined or at best implementation-specific, while allowing sensible operations.

The disord package in use

I will illustrate the package by a few examples of legal and illegal code. First create a simple disord object:

set.seed(0)
a <- rdis()    # a random disord object
a
#> A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
#> [1] 9 4 7 1 2 6 3 8 5
#> (in some order)

We may perform various operations on this object:

a+4
#> A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
#> [1] 13  8 11  5  6 10  7 12  9
#> (in some order)
a > 5
#> A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
#> [1]  TRUE FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE
#> (in some order)
a[a<6]
#> A disord object with hash 1cb2c1cb8b5cb3c58e69ffcc5f88340cbdc6abbd and elements
#> [1] 4 1 2 3 5
#> (in some order)

with no difficulty. But if we try to find elements of a with a particular offset or offsets, the system returns an error:

a[1]
#> Error in .local(x, i, j = j, ..., drop): if using a regular index to extract, must extract each element once and once only (or none of them)
a[c(2,3)]
#> Error in .local(x, i, j = j, ..., drop): if using a regular index to extract, must extract each element once and once only (or none of them)

This is because the elements of a are stored in an implementation-specific order and there is no such thing as the “first” element. We may manipulate elements of a by reference to their values but not by their position in the vector:

a[a<3] <- 0  # round small elements down
a
#> A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
#> [1] 9 4 7 0 0 6 3 8 5
#> (in some order)

Replacement methods can access subsets where this makes sense:

x <- disord(1:10)
x
#> A disord object with hash 65e11d78de79b7f584068ad856749e3748cb837c and elements
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> (in some order)
x[x<3] <- x[x<3] + 100
x
#> A disord object with hash 65e11d78de79b7f584068ad856749e3748cb837c and elements
#>  [1] 101 102   3   4   5   6   7   8   9  10
#> (in some order)

Two distinct disord objects

If we create another disord object, b:

b <- rdis()
b
#> A disord object with hash 488e1c6f4e2c062379d47b5511730a9785661318 and elements
#> [1] 2 3 8 1 5 6 9 7 4
#> (in some order)

Then a and b have the same length, but adding them vectorially is forbidden because the order of their elements is implementation-specific:

a+b
#> disordR discipline error in:
#> a + b
#> 
#> hash codes 5b7279f3c05d00cf1e8f999a755151e0451c56ec and 488e1c6f4e2c062379d47b5511730a9785661318 do not match
#> Error in check_matching_hash(e1, e2, match.call()): stopping

Also, replacement methods that access cross-referenced locations are forbidden:

a[b < 4] <- 5
#> disordR discipline error in:
#> .local(x = x, i = i, j = j, value = value)
#> 
#> hash codes 5b7279f3c05d00cf1e8f999a755151e0451c56ec and 488e1c6f4e2c062379d47b5511730a9785661318 do not match
#> Error in check_matching_hash(x, i, match.call()): stopping

(observe carefully that a[b<14] <- 5 is legal). However, sometimes one knows that two disord objects have the same ordering (perhaps a is the key, and b the value, of an associative array). In this case one may cross-reference them provided that the hash codes of the two objects agree:

a <- rdis()
b <- disord(sample(9),hash(a))
a
#> A disord object with hash 909ab9cb9afebb8a5109f17b277b37d7e6b1aaa1 and elements
#> [1] 7 1 9 5 6 8 4 2 3
#> (in some order)
b
#> A disord object with hash 909ab9cb9afebb8a5109f17b277b37d7e6b1aaa1 and elements
#> [1] 5 2 8 6 1 4 3 9 7
#> (in some order)

See how a and b have the same hash code. Then, although the elements of a and b are stored in an implementation-specific (and thus unknown) order, whatever order it is is the same in both objects and they are relatable:

a+b
#> A disord object with hash 909ab9cb9afebb8a5109f17b277b37d7e6b1aaa1 and elements
#> [1] 12  3 17 11  7 12  7 11 10
#> (in some order)
a[b < 0.5]
#> integer(0)
a[b < 0.2] <- b[b < 0.2]
a
#> A disord object with hash 909ab9cb9afebb8a5109f17b277b37d7e6b1aaa1 and elements
#> [1] 7 1 9 5 6 8 4 2 3
#> (in some order)

Comparison with python

A disord object is comparable with python arrays with the proviso that one is only allowed to access or manipulate elements via list comprehensions. See the following python session:

~ % python3
Python 3.9.5 (default, May  4 2021, 03:33:11) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *
>>> a = random.rand(5)
>>> b = random.rand(5)
>>> a
array([0.13275574, 0.07243463, 0.0543058 , 0.36633955, 0.73795801])
>>> b
array([0.14934221, 0.11321413, 0.6135964 , 0.53558058, 0.6396702 ])
>>> [i**2 for i in a]
[0.017624086607707354, 0.005246776214236293, 0.002949120389839953, 0.1342046637421116, 0.54458202262916]
>>> [i+j for i,j in zip(a,b)]
[0.28209795105056, 0.18564876373593042, 0.6679022004516395, 0.901920128499422, 1.377628206483919]
>>> 

Note that in the last line zip() is used to relate a and b which is accomplished in the package by explicitly setting the hash code.

disordr's People

Contributors

robinhankin avatar

Stargazers

Srikanth K S avatar

Watchers

James Cloos avatar  avatar

disordr's Issues

Matrix dependency issue

Hello,

You are receiving this e-mail because you are listed as the maintainer
of a CRAN/Bioc package with 'Matrix' in its Depends or Imports.

We, the authors of 'Matrix', have detected that your dependency is not
strict enough, because you either (a) depend on a minimum version of
'Matrix' that is too old, or (b) do not specify a minimum even though
one is needed. We recommend that you use at least the following:

     Package            Depends/Imports
 [1,] BASiCS             Matrix (>= 1.5-0)
...[snip]...
[21,] disordR            Matrix (>= 1.3-3)
...[snip]...
[50,] variancePartition  Matrix (>= 1.3-0)

Unfortunately, the need for such a change is somewhat subtle and not
detected in CRAN's checks. The main issues are as follows.

Due to the details of your NAMESPACE, your package binaries cache S4
class definitions and/or methods from 'Matrix'. You can find these
cached objects "hidden" in your package namespace, in lists named
.C and .T:, e.g.,

grep("^[.][CT]", names(asNamespace("")), value = TRUE)

If your binary was built against an old version of 'Matrix', then
it is possible for cached classes and methods to differ from the
corresponding ones defined in the latest 'Matrix'.

In the worst case, behaviour seen by two users with identical versions
of your package and identical versions of 'Matrix' can differ depending
on the version of 'Matrix' available when your binary was built.

A sufficiently strict 'Matrix' version requirement avoids these issues.
Hence, going forward, we will notify package maintainers as we update
'Matrix' of potentially "stale" dependencies.

Please let us know if you have further questions, maybe after browsing
the recent R-devel thread on this topic, here:

https://stat.ethz.ch/pipermail/r-devel/2022-September/081971.html

Thank you,
Mikael, Martin, and Doug

replacement bug

> a <- disord(1:4)
> a
A disord object with hash 973fab30f5c177d6692176fc5229c843fb7494ba and elements
[1] 1 2 3 4
(in some order)
> a[] <- c(7,7,7,7)
Error in .local(x, i = i, j = j, ..., value) : 
  length(value) == 1 is not TRUE
> 

Above we would expect a to become a vector of 7's. But it returns an error.

extracting no elements bug

> x <- 1:3
> x[F]
integer(0)
> x[c(F,F,F)]
integer(0)
> 
> x <- disord(1:3)
> x[F]
Error in .local(x, i, j = j, ..., drop) : 
  if using a regular index to extract, must extract each element once and once only
> x[c(F,F,F)]
Error in .local(x, i, j = j, ..., drop) : 
  if using a regular index to extract, must extract each element once and once only
> 

When x is an integer the extraction works fine, but when x is a disord, it fails even though I would expect the same result. This actually affects the clifford package (which fails a test if we change the default of disord() to be disord(...,drop=TRUE)).

bug in is.na<-()

Following example taken from misc.Rd:

 a <- disord(c(1,3,4))
 a
A disord object with hash b4b1eb91ca18b2ae8de2b461ed2e57c9184a8f41 and elements
[1] 1 3 4
(in some order)
 is.na(a) <- c(T,F,F)
 a
A disord object with hash b4b1eb91ca18b2ae8de2b461ed2e57c9184a8f41 and elements
[1] NA  3  4
(in some order)

Above is clearly a bug: the last line should return an error.

extraction bug

Look:

> a <- disord(sample(30))
> b <- disord(sample(30))
> a[b>3]
A disord object with hash 2e0b2ff0deb9785ef80a8eb110d1ca70e2042685 and elements
 [1] 21 24 28 11 18 30 17 27  5 12 22 15  6 20 23  8  2 25  1  7 19 10 16 14 29
[26]  9  3
(in some order)
> 

Above, a[b>3] should return an error, but doesn't.

calculating hash

currently in the code I use several lines like disord(x,digest::sha1(c(hash(x),i))) and what we need is a single definition near the top of disord.R that specifies once and for all the way to calculate a hash code. And this function can be used by freealg and clifford in the same way.

mvp coeffs work well as they use S3

In the mvp package, the mvp_coeffs class works nicely in the sense that there is no need to define functions like sin(), as they are just inherited from vectors. It would be nice to modify the disordR package so that this (or something like it) works.

factors

Factors behave strangely:

> p <- factor(c('a','b','a','a','b','x'))
> p
[1] a b a a b x
Levels: a b x
> disord(p)
A disord object with hash ccba70ec3e61b730ddbe9b0cc0b8ed2f92b345a6 and elements
[1] 1 2 1 1 2 3
(in some order)
> 

See also issue #25

for() loops

Look:

> x <- disord(c(4,2,1,2))
> x
A disord object with hash 6c08f4289697119188dfd166d674114d8b15a8fe and elements
[1] 4 2 1 2
(in some order)
> for(i in x){print(i)}
[1] 4
[1] 2
[1] 1
[1] 2
> 

See that the for() loop imposes an ordering on x, as it identifies "4" as the first element, "2" as the second, and so on. This is equivalent to using elements(). I don't think this is a bug as such but it should be documented.

documentation infelicity in drop.Rd

Now that we have

disord <- function(v,h,drop=TRUE){ ...}

Much of the documentation at drop.Rd is outdated and possibly misleading. I think it is probably best to have a specific help page (rather than document the issue at disord.Rd) but it's not clear yet.

CRAN error from R-devel

Email from Brian Ripley telling me that CRAN was returning an error:

* installing *source* package ‘disordR’ ...
** package ‘disordR’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error : in method for ‘[<-’ with signature ‘x="disord",i="missing",j="missing"’:  arguments (‘value’) after ‘...’ in the generic must appear in the method, in the same place at the end of the argument list
Error: unable to load R code in package ‘disordR’
Execution halted
ERROR: lazy loading failed for package ‘disordR’
* removing ‘/data/gannet/ripley/R/packages/tests-clang/disordR.Rcheck/disordR’

extract all elements error message misleading

> d <- disord(1:3)
> d[c(1,2,3,1,2,3)]
Error in .local(x, i, j = j, ..., drop) : 
  if using a regular index to extract, must extract all elements
>

Above, the error message is slightly misleading as I did extract all the elements. But the idiom is behaving correctly by returnin an error, as the output is not well-defined.

feedback from CRAN

Thanks,

Please always write package names, software names and API (application
programming interface) names in single quotes in title and description.
e.g: --> 'disordR'

If there are references describing the methods in your package, please
add these in the description field of your DESCRIPTION file in the form
authors (year) doi:...
authors (year) arXiv:...
authors (year, ISBN:...)
or if those are not available: https:...
with no space after 'doi:', 'arXiv:', 'https:' and angle brackets for
auto-linking.
(If you want to add a title as well please put it in quotes: "Title")

Please add \value to .Rd files regarding exported methods and explain
the functions results in the documentation. Please write about the
structure of the output (class) and also what the output means. (If a
function does not return a value, please document that too, e.g.
\value{No return value, called for side effects} or similar)
Missing Rd-tags:
c.Rd: \value
disord.Rd: \value
drop.Rd: \value
pmin.Rd: \value

Please fix and resubmit.

Best,
Julia Haider

error

> a <- rdis()
> x <- a^2 + 0.2
> a[a<0.5] <- x[a<0.5]
Error in .local(x, i, j = j, ..., value) : 
  consistent(x[i], value) is not TRUE
>

I think the last line above should not be an error: it has a clear meaning.

extraction bug

Look:

> a <- disord(c(1,2,3,3))
> a[a==3]
[1] 3 3
> 

I would expect the last line to return a disord object, not a vector.

a[] bug

look:

> a <- rdis(6)
> a
A disord object with hash 0391730bcf1a203ee697791935021da1727c4966 and elements
[1] 0.47487254 0.09885473 0.06581562 0.51911187 0.05166260 0.94916747
(in some order)
> a[]
[1] 0.47487254 0.09885473 0.06581562 0.51911187 0.05166260 0.94916747
attr(,"hash")
[1] "0391730bcf1a203ee697791935021da1727c4966"
> 

On the last line, I would expect a[] to either return a disord object or an error.

zapsmall()

following the fixing of issue #14 I find that zapsmall() still fails, but for a different reason:

> a <- as.mvp('x+2*y')
> zapsmall((1+a/10)^6)
Error in abs(x[!ina]) : non-numeric argument to mathematical function
> 

but this time the problem is in is.na():

 is.na((1+a/10)^6)
 names  power coeffs 
 FALSE  FALSE  FALSE 
> 

Not sure how to approach this.

which()

Function which() breaks the discipline:

> a <- disord(c(15,3,4,2,6))
> a
A disord object with hash 861a8c21a2410ba14a084f8f045e98a072694556 and elements
[1] 15  3  4  2  6
(in some order)
> which(a==4)
[1] 3
> 

replacement methods not returning an error

If an extraction operation returns a dropped value, the replacement methods can incorrectly return a meaningless value:

> a <- disord(c(1,1,-1,-1))
> a
A disord object with hash bda785a4f305ab7cff0cd25e77c7f76e4cbb6bbb and elements
[1]  1  1 -1 -1
(in some order)
> a[a>0] <- 5:6
> a
A disord object with hash bda785a4f305ab7cff0cd25e77c7f76e4cbb6bbb and elements
[1]  5  6 -1 -1
(in some order)
> 

Above we see a[a>0] <- 5:6 returning a value, but the idiom should return an error.

This was causing problems in the freealg package:

RobinHankin/freealg#31

drop

If the output is length-1, it might be reasonable to ask for a non-disord object to be returned. Currently:

> a <- disord(sample(55))
> a[a==1]
A disord object with hash b48c17a2ac82601ff38df374f87d76005fb61cbd and elements
[1] 1
(in some order)
> 

But it might be nice to have

> a[a==1,drop=TRUE]
[1] 1
>

sapply()

Issue #5 refers. sapply() does not work as desired:

> a <- list(1,1:2,8:4,30)
> sapply(a,length)
[1] 1 2 5 1
> sapply(disord(a),length)
Error in as.list.default(X) : 
  no method for coercing this S4 class to a vector
> 

I want sapply() to return a disord object with elements 1 2 5 1 (in some order).

unhelpful error message from `unlist()`

Look:

> a <- disord(list(1,1:4))
> unlist(a)
Error in .local(x, recursive) : length(out) == length(x) is not TRUE
> 

The error should come from disordR, not wherever that error came from.

.value() for disindex objects

Four observations:

(1) .value() should return a disord
(2) it should be exported (so that thedismat package, for example, can use it)
(3) it should not have a dot before the name
(4) it should be called values(), not value()

list extraction

Coercing a list to a disord object allows one to abuse double-square brackets:

> a <- disord(list(6:7,3:9))
> a
A disord object with hash 44c1e2907fd0c650d42d794ea469e8b2b51e5a75 and elements
[[1]]
[1] 6 7

[[2]]
[1] 3 4 5 6 7 8 9

(in some order)
> a[[1]]
[1] 6 7
> 

Above, I would expect a[[1]] to return an error on the grounds that the order of the elements is implementation -specific.

`a[] <- x` changes the hash

a <- disord(c(1,1,1),drop=FALSE)
a
A disord object with hash d5c3a970db727f70b815b55ac2f42de4129325fa and elements
[1] 1 1 1
(in some order)
a[] <- 1:3
a
A disord object with hash fe50fd4ad46d4410a866d82ffcc8686c763dc2f8 and elements
[1] 1 2 3
(in some order)

Above, a[] <- 1:3 should work as it does not break disord discipline, but note that it changes the hash. I do not think this is correct, I think the hash of a should not change under these circumstances.

paste() problem

Look:

paste(disord(letters),"3",sep="")
 [1] "a3" "b3" "c3" "d3" "e3" "f3" "g3" "h3" "i3" "j3" "k3" "l3" "m3" "n3" "o3"
[16] "p3" "q3" "r3" "s3" "t3" "u3" "v3" "w3" "x3" "y3" "z3"
> 

the output should be a disord object, not a vector.

extract all elements

Currently extraction by number is disallowed. But sometimes it makes sense:

> a <- disord(runif(5))
> a[1:5]
Error in .local(x, i, j = j, ..., drop) : 
  cannot use a regular index to extract, only a disord object
> 

Above, it would be reasonable to return a because all elements have been selected.

%in%

> a <- disord(sample(1:4,30,replace=TRUE))
> a
A disord object with hash 265bf3d17dfa8c05ecd56f28db62710ba3ffd609 and elements
 [1] 1 1 1 4 1 2 3 2 1 4 1 1 1 1 4 1 1 2 2 1 4 1 3 2 3 4 4 4 4 4
(in some order)
> a[a %in% 1:2] 
Error in .local(x, i, j = j, ..., drop) : 
  if using a regular index to extract, must extract all elements

Above, I would expect the last line to return something sensible. Also the error message is outdated.

interesting error message

set.seed(0)
(a <- rdis())
A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
[1] 9 4 7 1 2 6 3 8 5
(in some order)
a[a<3] <- a[a<5] + 1000
Warning message:
In jj[elements(i)] <- elements(value) :
number of items to replace is not a multiple of replacement length
a
A disord object with hash 5b7279f3c05d00cf1e8f999a755151e0451c56ec and elements
[1] 9 4 7 1004 1001 6 3 8 5
(in some order)

lists

I discover, to my unalloyed delight, that lists work as desired:

> a <- list(1,1:2,8:4,30)
> disord(a)
A disord object with hash edad39a516fce76fdca82c9462dea3b815e9f02e and elements
[[1]]
[1] 1

[[2]]
[1] 1 2

[[3]]
[1] 8 7 6 5 4

[[4]]
[1] 30

(in some order)
> 

. . . but this needs documenting.

suggestions to publish some of the work

Dear Robin,

Last year ISSAC allowed remote participation but I am not sure what is the policy for this year.

In the case you find it useful, here are some other venues you may be interested in:
CASC conference: https://www.casc-conference.org
SYNASC conference: https://synasc.ro
ACA conference: https://scale.gtu.edu.tr/aca.html
Journal of Symbolic Computation: https://www.sciencedirect.com/journal/journal-of-symbolic-computation
Journal of Software for Algebra and Geometry: https://msp.org/jsag/about/journal/about.html

replacement methods too lax

Look:

> a <- disord(1:10)
> a[a<5] <- c(113,116,112,119)
> a
A disord object with hash 65e11d78de79b7f584068ad856749e3748cb837c and elements
 [1] 113 116 112 119   5   6   7   8   9  10
(in some order)
> 

Above, the second line works but it should not: the RHS has an order, and the LHS does not.

a[] <- 5 should work

Look:

> a <- 1:5
> a[] <- 7
> a
[1] 7 7 7 7 7

The above idiom works fine. But:

> a <- rdisord()
> a[] <- 3
Error in a[] <- 3 : object of type 'S4' is not subsettable
> 

. . . and it really should work. See also issue #3

logic for disord objects

I didn't think I'd need to implement logic, so didn't do it, but:

> a <- rdis(6)
> a
A disord object with hash ee2f3004f17069125d8c30d8d368953679cc50e6 and elements
[1] 0.7008326 0.2164962 0.3027965 0.2725064 0.5944444 0.9378613
(in some order)
> a>0.3
A disord object with hash ee2f3004f17069125d8c30d8d368953679cc50e6 and elements
[1]  TRUE FALSE  TRUE FALSE  TRUE  TRUE
(in some order)
> a < 0.9
A disord object with hash ee2f3004f17069125d8c30d8d368953679cc50e6 and elements
[1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
(in some order)
> (a>0.3) & (a<0.9)
Error in (a > 0.3) & (a < 0.9) : 
  No logic currently implemented for disord objects
> 

above, I would expect the last line to give an appropriate Boolean disord object.

question

I have a new S4 class "foo" and want to use it to extract elements
from a vector. But see the following:

rstudio % R --quiet --vanilla
> R.Version()$version.string
[1] "R version 4.1.0 (2021-05-18)"
> setClass("foo",slots=c(x="vector"))
> (a <- new("foo",x=1:3))
An object of class "foo"
Slot "x":
[1] 1 2 3

> setMethod("[",signature=c(x="ANY",i="foo"),function(x,i){"hello"})
> letters[a]
Error in letters[a] : invalid subscript type 'S4'
> 

Desired behaviour is for "letters[a]" on the last line to dispatch to
the "hello" function, but I get this error instead. What is wrong
with my understanding?

named vectors

The names of a named vector are lost:

> dput(disord(c(b=5,c=2,a=6)))
new("disord", .Data = c(5, 2, 6), hash = "b7cf7d05a06606b919bc758c0804aabae4ca9c9b")
> 

It seems to me that the name/value pairs are not stored in any particular order, which would suggest that a named vector might be storable in a similar way to a disord object. See also
RobinHankin/hyper2#101 and RobinHankin/hyper2#104

pmin() seems to work

Look:

> a <- rdis()
> b <- a*2-0.5
> pmin(a,b)
A disord object with hash 91ae489c424fb97f79660fb26d7e55fd7540a5c2 and elements
[1]  0.75251960 -0.03254402  0.98480714
[4]  0.72937949  0.60269093  0.14233462
[7]  0.51988598  0.95873991  0.31990565
(in some order)
> 

I guess it is because of the new lapply(), but either way we can lose that pmindis() and pmaxdis() stuff.

length

Setting the length of a disord object does not return an error:

> (a <- disord(1:5))
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
[1] 1 2 3 4 5
(in some order)
> length(a) <- 7
> a
[1]  1  2  3  4  5 NA NA
> a <- disord(1:5)
> length(a) <- 3
> a
[1] 1 2 3
> 

and it should.

bug in ==

> disord(1:5) == 2
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
[1] FALSE  TRUE FALSE FALSE FALSE
(in some order)
> 2 == disord(1:5)
Error in disord_compare_any(e2, e1) : object '.Generic' not found
> 

First call works fine, second one fails but should work

empty disord objects should be dropped too

If an extraction operation returns a disord object with zero elements, it really should drop() the result. But:

> a <- disord(1:5)
> a[a>6]
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
integer(0)
(in some order)
> 

Also, drop() does not behave as expected:

 a <- disord(1:5)
> o <- a[a>6]
> o
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
integer(0)
(in some order)
> drop(o)
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
integer(0)
(in some order)
> 

diff

diff() should fail for a disord object but:

> (a <- rdis())
A disord object with hash 4709b30137f7d8ac6460092e0979ed752ede37da and elements
[1] 6 4 1 8 7 2 9 3 5
(in some order)
> diff(a)
[1] -2 -3  7 -1 -5  7 -6  2
attr(,"class")
[1] "disord"
attr(,"class")attr(,"package")
[1] "disordR"
> 

bug in replacement method

Look:

> a <- disord(c(1,4,3,2))
> a[a<3]  <- c(55,56)
> a
A disord object with hash 866f83456db41e4b63abc2422390a9f0034741ff and elements
[1] 55  4  3 56
(in some order)
> 

The assignment should return an error, as it is undefined. I noticed this when playing with the mvp package:

a <- rmvp()
coeffs(a)[coeffs(a) < 4] <- c(1001,1002,1003)

bug in power

> disord(1:5)^2
A disord object with hash c8d5cf2b423f09441a6e59a0bb2b2f6cd152d234 and elements
[1] 1 0 1 0 1
(in some order)
> 

unhelpful error message

> 
> disord(1:2) + 1:2
disordR discipline error in:

disord(1:2) + 1:2
Error in hash(e2) : 
  trying to get slot "hash" from an object of a basic class ("integer") with no slots
> 

bug in disords of disords

It should be possible to have a disord object which is a list whose elements are themselves disord objects. But:

> disord(list(disord(1:3),disord(5:8),disord(8:18)))
Error: sha1() has no method for the 'disord' class
> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.