Skip to contents

The disord class provides basic arithmetic and extract/replace methods for disord objects.

Class index is taken from the excellent Matrix package and is a setClassUnion() of classes numeric, logical, and character.

Methods

[

signature(x = "disord", i = "ANY", j = "ANY"): ...

[

signature(x = "disord", i = "index", j = "index"): ...

[

signature(x = "disord", i = "index", j = "missing"): ...

[

signature(x = "disord", i = "missing", j = "index"): ...

[

signature(x = "disord", i = "missing", j = "missing"): ...

[

signature(x = "disord", i = "matrix", j = "missing"): ...

[<-

signature(x = "disord", i = "index", j = "index"): ...

[<-

signature(x = "disord", i = "index", j = "missing"): ...

[<-

signature(x = "disord", i = "missing", j = "index"): ...

[<-

signature(x = "disord", i = "matrix", j = "missing"): ...

[<-

signature(x = "disord", i = "missing", j = "missing"): ...

[[

signature(x = "disord", i = "index"): ...

[[<-

signature(x = "disord", i = "index",value="ANY"): ...

[

signature(x="disord",i="disindex",j="missing",drop="ANY"): ...

[

signature(x="disord",i="disindex",j="ANY",drop="ANY"): ...

[

signature(x="ANY",i="disindex",j="ANY",drop="ANY"): ...

[

signature(x="disord",i="disindex",j="missing",value="ANY"): ...

[

signature(x="disord",i="disindex",j="ANY",value="ANY"): ...

[<-

signature(x="disord",i="disindex",j="missing",drop="ANY"): ...

[[

signature("disord",i="disindex"): ...

[[

signature("ANY",i="disindex"): ...

[[<-

signature(x="disord",i="disindex",j="missing",value="ANY") ...

[[<-

signature(x="ANY",i="disindex",j="ANY",value="ANY") ...

The extraction method takes a drop argument which if TRUE, returns the drop() of its value. Extraction, as in x[i], is rarely useful. It is only defined if one extracts either all, or none, of the elements: anything else is undefined. Note that the hash code is unchanged if all elements are extracted (because the order might have changed) but unchanged if none are (because there is only one way to extract no elements).

Missing arguments for extraction and replacement are slightly idiosyncratic. Extraction idiom such as x[] returns an object identical to x except for the hash code, which is changed. I can't quite see a sensible use-case for this, but the method allows one to define an object y <- x[] for which x and y are incompatible. Replacement idiom x[] <- v always coerces to a vector.

Double square extraction, as in x[[i]] and x[[i]] <- value, is via (experimental) disindex functionality.

Author

Robin K. S. Hankin

Note

Package versions prior to disordR_0.0-9-6 allowed idiom such as


    a <- disord(1:9)
    a[a<3] + a[a>7]
  

but this is now disallowed. The issue is discussed in inst/note_on_extraction.Rmd.

See also

Examples

a <- disord(sample(9))
a
#> A disord object with hash f43ce4811f8bfa51ec2b7f0c80c8a3d508df389f and elements
#> [1] 6 1 8 5 2 4 7 3 9
#> (in some order)
a + 6*a^2
#> A disord object with hash f43ce4811f8bfa51ec2b7f0c80c8a3d508df389f and elements
#> [1] 222   7 392 155  26 100 301  57 495
#> (in some order)
a[a>5]  # "give me all elements of a that exceed 5"
#> A disord object with hash 0301153232aac74fde20da058aa6f37fcba2c809 and elements
#> [1] 6 8 7 9
#> (in some order)

a[] # a disord object, same elements as 'a', but with a different hash
#> A disord object with hash 31788b4569d87b65d2d4250514a8e975b6711053 and elements
#> [1] 6 1 8 5 2 4 7 3 9
#> (in some order)

a[a<5] <- a[a<5] + 100  # "replace all elements of 'a' less than 5 with their value plus 100"
a
#> A disord object with hash f43ce4811f8bfa51ec2b7f0c80c8a3d508df389f and elements
#> [1]   6 101   8   5 102 104   7 103   9
#> (in some order)

## Following expressions would return an error if executed:
if(FALSE){
  a[1]
  a[1] <- 44
  a[1:2] <- a[3:4]
}

b <- disord(sample(9))
## Following expressions would also return an error if executed:
if(FALSE){
  a+b  # (not really an example of extraction)
  a[b>5]
  a[b>5] <- 100
  a[b>5] <- a[b>5] + 44
}