Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

string-boundary

Flag grepl("^abc", x) and grepl("abc$", x), single-anchored fixed-string matches that are the clearer startsWith(x, "abc") and endsWith(x, "abc")—they state the prefix/suffix test directly and skip regex compilation.

The rule fires only on the clean shape (two positional arguments, a one-end-anchored plain-literal pattern) and only when grepl resolves to base R. The fix is unsafe: on NA or non-character input startsWith/endsWith diverge from grepl (NA vs FALSE, an error vs coercion).

Anchored fixed-string matches:

grepl("^abc", x)
warning: string-boundary
 --> example.R:1:1
  |
1 | grepl("^abc", x)
  | ^^^^^^^^^^^^^^^^ single-anchor `grepl()` is the clearer `startsWith()`
  = help: Use `startsWith()`.