djvanderlaan / ldat

(Statistical) function for working with lvec objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in indexing ldat with `drop` argument.

djvanderlaan opened this issue · comments

ecent improvements in R-devel (the development version of R, to
become R 4.0.0 next April), notably its head() and tail() methods

did contain a non-backward compatible change in the default
method, which we deemed to be a bug-fix
i.e. consistency-improving change.

As consequence, the CRAN checks of your 'reclin' package now
show that at least one vignette no longer builds, and some
investigation shows that it is indeed when using 'head(p)'
in the following snippet from your vignette :

library(reclin) ## --> pkg 'lvec', then many warnings about masking base etc
library(dplyr)  ## .... more warnings about  masking ...
data("town_names")
## simplified in one (by MM):
town_names$clean_name <- gsub("0", "o",
                              gsub("[^[:alnum:]]", "", town_names$name))

p <- pair_blocking(town_names, town_names) %>%
   filter_pairs_for_deduplication() %>%
   compare_pairs("clean_name", default_comparator = jaro_winkler()) %>%
   score_simsum() %>%
   select_threshold(0.88)

## MM:
class(p) # "compare"        "pairs_blocking" "pairs"          "ldat"
methods(head)
##==> this calls  head.default :

head(p) #--> head.default() failing  (!!)  [indeed, it applies it to columns, not rows !]
"
Error in `[.ldat`(x, 1:6, , drop = FALSE) : Invalid indices.
"

## Reason: old  head.default(x, n)  gave   x[seq_len(n)]
##         the new one does                x[seq_len(n), drop=FALSE] :
a <- structure(array(1:7, 7), class="foo")
cat("a: "); str(a); cat("head(a,1): "); str(h1 <- head(a,1))
"
R:         head(a,1):  int 1
R-devel:   head(a,1):  int [1(1d)] 1
"

##===> The "bug" is in package 'ldat', notably it `[` method !
##          ---                 ^^^^              ==========
## ===>  ~/R/Pkgs/ldat/R/indexing.R : The `[.ldat` needs to work correctly with 'drop = FALSE'
## ===>  I have added that argument in my version of ldat
## `[.ldat` <- function(x, i, j, drop = FALSE, ..., range = NULL, clone = TRUE) {

I append a version of ldat/R/indexing.R with which the above
'reclin' example works.

Note that 'lvec' may need a similar adjustment to its [.lvec
method.
Also note that 'ldat' (and 'lvec') ideally should contain their
own regression tests for this case (and maybe similar ones).
[This would have made it easier for the CRAN team and me to
guess that there is no problem in 'reclin' but in its
dependency 'ldat' ]

In such cases the CRAN team asks for an updated package within 2
weeks, i.e., Dec 23 ... but because this year's extended
CRAN-vacation over Christmas, you may take till Jan 8, 2020.

Please don't hesitate to ask about or discuss the issue with me
if you have questions, etc.