5

The perl() function is deprecated in the latest version of stringr in favor of regex(). However, I don't seem to be able to replicate the earlier behavior.

To capitalize the first letter of a vector of strings, this used to work:

name <- c("jim", "john", "bill")
str_replace(name, perl("^(.)"), "\\U\\1")

However, this no longer works:

str_replace(name, regex("^(.)"), "\\U\\1")

But using base R works:

gsub("^(.)", "\\U\\1", name, perl=TRUE)

Is there still a way to do this with the stringr package?

user2987808
  • 1,387
  • 1
  • 12
  • 28

1 Answers1

7

stringr is now powered by stringi instead which uses ICU regular expressions. If you want to implement PCRE, simply use sub directly while turning on perl = TRUE mode ...

sub('^(.)', '\\U\\1', name, perl=TRUE)
[1] "Jim"  "John" "Bill"
hwnd
  • 69,796
  • 4
  • 95
  • 132