Closed RobinHankin closed 2 years ago
But the functionality is not entirely present:
> a <- runif(10)
> pmax(a,0.5)
[1] 0.5000000 0.5000000 0.5000000 0.5000000 0.5000000 0.5000000 0.5111702
[8] 0.5000000 0.7380832 0.5000000
But pmax()
does not work for disord
objects and length-one vectors:
> a <- rdis()
> a
A disord object with hash c9b49b1566b6d38ecc77c5774bf61681c684692b and elements
[1] 0.08796295 0.13858344 0.80037993 0.37455733 0.18298922 0.03930161 0.68088122
[8] 0.33788059 0.42316731
(in some order)
> pmax(a,0.5)
Error in mmm < each : length(e2) == 1 is not TRUE
>
Function base::pmax()
fails at the line if (isS4(change <- mmm < each) && (nS4 || !isS4(each))) change <- as(change, "logical")
and that fails because comparisons [here "<
"] do not work between disord objects and vectors all of which are the same entry:
> disord(1:10) < rep(5,10)
Error in disord(1:10) < rep(5, 10) : length(e2) == 1 is not TRUE
>
Commit cf9a3641fea617beb1cfa865db fixed the "<" issue but not pmax()
; the error message has changed:
> pmax(disord(1:10),4)
Error in .local(x, i, j = j, ..., value) :
cannot use a regular index to extract, only a disord object
>
The problem is now here:
if (isS4(change <- mmm < each) && (nS4 || !isS4(each)))
change <- as(change, "logical")
and the error is caused by this:
> jj <- (disord(1:10)>5)
> as(jj,"logical")
[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE
>
The problem is that as(jj,"logical")
should give a disord
object, but the hash is lost. And this is definitely wrong because losing the hash means that an order is imposed.
We need
setAs("disord","logical",function(from){disord(as.logical(elements(from)),hash(from))})
(which incidentally seems to make pmax()
work) but there are other coercion methods to do and it would be better to do them all at once.
Look:
I guess it is because of the new
lapply()
, but either way we can lose thatpmindis()
andpmaxdis()
stuff.