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

a[] # a disord object, same elements as 'a', but with a different hash
#> A disord object with hash b0a3f865150faf428c1523c11cc1fb05717d5e1d and elements
#> [1] 6 9 5 3 4 1 7 8 2
#> (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 f323e8c814b296c21ab092c17ad9f0c7286ad20e and elements
#> [1]   6   9   5 103 104 101   7   8 102
#> (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
}