HenrikBengtsson / Wishlist-for-R

Features and tweaks to R that I and others would love to see - feel free to add yours!
https://github.com/HenrikBengtsson/Wishlist-for-R/issues
GNU Lesser General Public License v3.0
134 stars 4 forks source link

WISH: Make grep(pattern, ...) produce an error if length(pattern) > 1 - not just a warning #122

Open HenrikBengtsson opened 3 years ago

HenrikBengtsson commented 3 years ago

Issue

The grep() family of functions will produce a warning if pattern specified more than one regular expression, e.g.

> pattern <- c("Volvo", "Fiat")
> grep(pattern, rownames(mtcars))
[1] 32
Warning message:
In grep(pattern, rownames(mtcars)) :
  argument 'pattern' has length > 1 and only the first element will be used

I don't think that is ever anything other than a coding mistake, i.e. a bug.

Suggestion

Instead of a warning, produce an error:

Error in grep(pattern, rownames(mtcars)) : 
  argument 'pattern' has length != 1

This applies to functions:

The above was verified on R 4.0.4.

HenrikBengtsson commented 1 year ago

Feature request PR#18577 was filed to BugZilla on 2023-08-09.