tidyverse / stringr

A fresh approach to string manipulation in R

Home Page:https://stringr.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New `str_view()` does not fully replace old `str_view()` and deprecated `str_view_all()`

mgarbuzov opened this issue · comments

This change in the recent patch doesn't seem to do what it is intending to do.

From the changelog: It defaults to displaying all matches, making str_view_all() redundant (and hence deprecated) (#455).

It seems there's been a confusion between what a "match" is. Some people used it to mean a pattern within an element, and others a whole element of a vector.

For example, the match = NA argument here str_view(c("abc", "def", "fghi"), "e", match = NA) can be used to show all elements of a vector, whether they contain a matching pattern or not, but there is no longer a way to control whether only the first or all patterns within elements are matched. For example: str_view("defe", "e") returns all two matches of "e" - a behaviour equivalent to deprecated str_view_all(), but it's no longer possible to get the behaviour of the old str_view() where it would match only one first pattern.

The issue #455 cited in the changelog proposes controlling this with the argument all_matches, but this isn't implemented, which suggests the turning of new str_view() into str_view_all() and deprecating of str_view_all() were premature.

In light of this confusion, could the arguments match and all_matches be better named all_elements and all_patterns or something along those lines?

There's no way to control if all matches or just one match is displayed, but if you can see all matches you can also see the first match. I don't think just seeing the first match is that common, so I deliberately dropped this ability. Sorry if that was unclear from the docs/news.