Skip to content

str_replace with empty pattern or pattern = boundary("character") Not implemented #210

@jimvine

Description

@jimvine

This appears to be a bug (either in the docs or the implementation) because the docs suggest that this is supported.

To reproduce:

stringr::str_replace("ABCDEF", "", " ")
Error: Not implemented

stringr::str_replace("ABCDEF", stringr::boundary("character"), " ")
Error: Not implemented

(Also affects str_replace_all().)

While the docs (?str_replace) say (under Arguments)

pattern Pattern to look for.
The default interpretation is a regular expression, as described in stringi-search-regex. Control options with regex().
Match a fixed string (i.e. by comparing only bytes), using fixed(x). This is fast, but approximate. Generally, for matching human text, you'll want coll(x) which respects character matching rules for the specified locale.
Match character, word, line and sentence boundaries with boundary(). An empty pattern, "", is equivalent to boundary("character").

(Emphasis mine.)

The equivalent does work in str_split():

stringr::str_split("ABCDEF", "")
[[1]]
[1] "A" "B" "C" "D" "E" "F"

stringr::str_split("ABCDEF", stringr::boundary("character"))
[[1]]
[1] "A" "B" "C" "D" "E" "F"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions