gagolews / stringi

Fast and portable character string processing in R (with the Unicode ICU)
https://stringi.gagolewski.com/
Other
304 stars 44 forks source link

Warning: longer object length is not a multiple of shorter object length #342

Closed geotheory closed 5 years ago

geotheory commented 5 years ago

Noting other issues around multiple patterns, I'm still unclear why this warning appears:

stringi::stri_detect_fixed(str = c('dogs and cats', 'cats and rabbits', 'dogs and rabbits'), 
      pattern = c('dog','cat'))
[1] TRUE TRUE TRUE
Warning message:
In stringi::stri_detect_fixed(str = c("dogs and cats", "cats and rabbits",  :
  longer object length is not a multiple of shorter object length

The output TRUE TRUE TRUE is fine. The documentation for stri_detect states for each string in str, if there is at least one match to a corresponding pattern, where pattern is defined as character vector defining search patterns. I don't see any reason why this should prompt a warning. Where does documentation say pattern vector length should have a length-factor relationship with str vector length? And what would be the rationale for such an implementation?

gagolews commented 5 years ago

This is vectorized in the same way c(1,10,100) * c(2, 3) yields c(2,30,200), see ?'stringi-arguments'

geotheory commented 5 years ago

Ah ok thanks. I wonder if the line for each string in str, if there is at least one match to a corresponding pattern might be potentially misleading? It seems to me the only way it can be accurate is for there to be much more to corresponding than is clear from the rest of the page. Bottom line is few of us have time to read all docs for a package!

Great package though - R would be much harder without :)