RobinHankin / disordR

https://robinhankin.github.io/disordR/
1 stars 0 forks source link

CRAN error from R-devel #50

Closed RobinHankin closed 1 year ago

RobinHankin commented 1 year ago

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’
RobinHankin commented 1 year ago

The original intent was as follows. Given

(x <- rdis())
A disord object with hash eae5c80d62b37b7296da701190e071aaf14533ec and elements
[1] 4 3 7 1 8 5 6 2 9
(in some order)

Then x[] <- 4 coerces x to a numeric vector. The intent of the drop argument was for x[drop=TRUE] <- 4 to make x a numeric vector and x[drop=FALSE] <- 4 make x a disord object (containing all 4s).

It is not clear to me that this is a sensible or consistent or desirable idea. Firstly, the "spirit" of x[] <- v is something like this:

In x[] <- 4, which elements of x are we replacing? Well, we sent nothing in square brackets so we replace every element of x. Compare x[x==4] <- 100 where we want to replace some selected element of x with 100.

Now if x[drop=FALSE] <- 4 were to work, this would lose this interpretation because the drop argument is not specifying elements to replace, it is telling us what to return. Now I can't see why anyone would want x[] <- v to coerce x to a disord object. If you did really want that, it is possible but admittedly a bit awkward:

library("disordR")
#> Loading required package: Matrix
(x <- rdis())
#> A disord object with hash 101f1879a7750a6697fc931721628fb5f377a621 and elements
#> [1] 8 3 5 4 9 6 7 1 2
#> (in some order)
x[T] <- 3
disord(x,drop=FALSE)
#> A disord object with hash e91db0e8bba4edb562bfc96b77e25841027ec357 and elements
#> [1] 3 3 3 3 3 3 3 3 3
#> (in some order)

Created on 2023-06-23 with reprex v2.0.2

On balance, I think if we want to replace every element of a disord object, we do so by sending nothing in square brackets; we then return the resulting object. This object should be coerced to a vector on the grounds that: (i) it always can be, and (ii) vectors are less restrictive than disord objects. Quite apart from all this, I can't figure out any non-kludgy way to implement a drop argument that furnishes previous behaviour.

RobinHankin commented 1 year ago

Working on the above error, sent updated package to winbuilder, which returns this, referring to [[<-():

Error : in method for '[[<-' with signature 'x="disord",i="index"':  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'