Closed RobinHankin closed 1 year ago
there is a similar problem with list extraction even for disords of numeric vectors:
> disord(c(8,1,2,3))[[2]]
[1] 1
>
I need a general set of methods for [[
.
But the big big big problem is that lapply()
is used on disordered lists in at least three packages (freealg
, mvp
, and stokes
). It might be best to treat this as a documentation issue and point out that lapply()
breaks disordR
discipline.
According to revdepcheck
, three packages are broken by removing support for [[
: freealg
, mvp
, and stokes
. But the local version of stokes
seems to work. Have already fixed freealg
and mvp
in https://github.com/RobinHankin/freealg/commit/22e41035f1094463eecdbb049713dce8090bfdf4 and https://github.com/RobinHankin/mvp/commit/bb81d4a3431ea2b91e564b274481ee3cefb8158e respectively, must remember to upload new versions to CRAN before finally resolving the disordR
issue.
Sometimes, idiom that works for list extraction has a natural interpretion for disord
lists:
> x <- list(5:6,1:5,2:7)
> x[[which(lapply(x,length)>5)]]
[1] 2 3 4 5 6 7
>
Now, this arguably should work for a disord list, but currently does not:
> x <- disord(x)
> x[[which(lapply(x,length)>5)]]
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'i' in selecting a method for function '[[': which() does not make sense for disord object
>
Above, the gloss would be "extract the single element of x
with length exceeding 5", which is disord-OK. But the problem is not with the list extraction; as the error messge says, the issue is which()
:
> which(lapply(x,length)>5)
Error in .local(x) : which() does not make sense for disord object
>
It is not clear to me whether implementing this is (a), desirable or (b), possible. But in any event, current behaviour is not adequately documented.
Closing, double square bracket extraction now covered by disind
indexing
Coercing a list to a
disord
object allows one to abuse double-square brackets:Above, I would expect
a[[1]]
to return an error on the grounds that the order of the elements is implementation -specific.