Skip to content

Commit 6688f1a

Browse files
committed
fix
1 parent 6da3a6c commit 6688f1a

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

pkg/DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Description: Implements an approximate string matching version of R's native
2323
vectors representing generic sequences. This package is built for speed and
2424
runs in parallel by using 'openMP'. An API for C or C++ is exposed as well.
2525
Reference: MPJ van der Loo (2014) <doi:10.32614/RJ-2014-011>.
26-
Version: 0.9.12
26+
Version: 0.9.13
2727
Depends:
2828
R (>= 2.15.3)
2929
URL: https://github.com/markvanderloo/stringdist
@@ -32,4 +32,4 @@ Suggests:
3232
tinytest
3333
Imports: parallel
3434
Encoding: UTF-8
35-
RoxygenNote: 7.2.3
35+
RoxygenNote: 7.3.2

pkg/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
version 0.9.13
2+
- Fixed issue with zero-length strings in 'qgrams' (Thanks to Brian Ripley
3+
for the notification and pointer to the origin of the problem)
4+
15
version 0.9.12
26
- apparently R_xlen_t is long long int on CLANG/Windows and long int on gcc-13/debian
37

pkg/R/phonetic.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' not be trusted. If non-ascii or non-printable ascii charcters are encountered, a warning
1818
#' is emitted.
1919
#'
20-
#' @seealso \code{\link{printable_ascii}}, \code{\link{stringdist-package}}
20+
#' @seealso \code{\link{printable_ascii}}
2121
#'
2222
#'
2323
#' @return

pkg/R/qgrams.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323
#' @example ../examples/qgrams.R
2424
#' @export
2525
qgrams <- function(..., .list=NULL,q=1L,useBytes=FALSE, useNames=!useBytes){
26+
stopifnot(is.numeric(q), length(q)==1, !is.na(q), q>=0)
2627
q <- as.integer(q)
2728

2829
if (!is.null(.list) && length(.list) == 0) .list=NULL
2930
L <- lapply(c(list(...),.list), as.character)
3031
if (length(L) == 0) return(array(dim=c(0,0)))
3132
L <- setnames(L)
33+
34+
if (q==0){
35+
return( matrix( sapply(L,function(x) sum(x==""))
36+
, ncol=1
37+
, dimnames = list(names(L), NULL)) )
38+
}
39+
40+
3241
L <- lapply(L,char2int)
3342

3443
v <- .Call("R_get_qgrams",L,as.integer(q),PACKAGE="stringdist")

pkg/R/stringdist.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#' }
6464
#' Or use \code{citation('stringdist')} to get a bibtex item.
6565
#'
66-
#' @name stringdist-package
66+
#' @aliases stringdist-package
6767
#' @docType package
6868
#' @useDynLib stringdist, .registration=TRUE
6969
#' @importFrom parallel detectCores

pkg/inst/tinytest/test_qgrams.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ options(sd_num_thread=2)
99
expect_equivalent(qgrams(NA,q=1), matrix(0,nrow=1,ncol=0)) # skip all
1010
expect_equivalent(qgrams(c("a","ab"), q=2), as.matrix(table("ab"))) # skip q>nchar
1111
expect_equivalent(qgrams(c("a"),q=2), matrix(0,nrow=1,ncol=0)) # skip all
12-
expect_equivalent(qgrams(c(''),q=0), as.matrix(table(''))) # empty string, q=0
12+
expect_equivalent(qgrams(c(''),q=0), matrix(table(''))) # empty string, q=0
1313

1414

1515
## qgrams

pkg/src/qgram.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ SEXP R_get_qgrams(SEXP a, SEXP qq){
546546
for ( int i=0; i < nstr; ++i ){
547547
str = (unsigned int *) INTEGER(VECTOR_ELT(strlist,i));
548548
nchar = length(VECTOR_ELT(strlist,i));
549-
if ( str[0] == NA_INTEGER
549+
if ( nchar == 0
550+
|| str[0] == NA_INTEGER
550551
|| q > nchar
551552
|| ( q == 0 && nchar > 0 )
552553
){

0 commit comments

Comments
 (0)