@@ -50,10 +50,7 @@ str_detect <- function(string, pattern, negate = FALSE) {
5050 regex = stri_detect_regex(string , pattern , negate = negate , opts_regex = opts(pattern ))
5151 )
5252
53- if (length(out ) == length(string )) {
54- names(out ) <- names(string )
55- }
56- out
53+ if (keep_names(string , pattern )) copy_names(string , out ) else out
5754}
5855
5956# ' Detect the presence/absence of a match at the start/end
@@ -93,8 +90,7 @@ str_starts <- function(string, pattern, negate = FALSE) {
9390 stri_detect_regex(string , pattern2 , negate = negate , opts_regex = opts(pattern ))
9491 }
9592 )
96- if (length(out ) == length(string )) names(out ) <- names(string )
97- out
93+ if (keep_names(string , pattern )) copy_names(string , out ) else out
9894}
9995
10096# ' @rdname str_starts
@@ -113,8 +109,7 @@ str_ends <- function(string, pattern, negate = FALSE) {
113109 stri_detect_regex(string , pattern2 , negate = negate , opts_regex = opts(pattern ))
114110 }
115111 )
116- if (length(out ) == length(string )) names(out ) <- names(string )
117- out
112+ if (keep_names(string , pattern )) copy_names(string , out ) else out
118113}
119114
120115# ' Detect a pattern in the same way as `SQL`'s `LIKE` and `ILIKE` operators
@@ -176,8 +171,7 @@ str_like <- function(string, pattern, ignore_case = deprecated()) {
176171
177172 pattern <- regex(like_to_regex(pattern ), ignore_case = FALSE )
178173 out <- stri_detect_regex(string , pattern , opts_regex = opts(pattern ))
179- if (length(out ) == length(string )) names(out ) <- names(string )
180- out
174+ if (keep_names(string , pattern )) copy_names(string , out ) else out
181175}
182176
183177# ' @export
@@ -191,8 +185,7 @@ str_ilike <- function(string, pattern) {
191185
192186 pattern <- regex(like_to_regex(pattern ), ignore_case = TRUE )
193187 out <- stri_detect_regex(string , pattern , opts_regex = opts(pattern ))
194- if (length(out ) == length(string )) names(out ) <- names(string )
195- out
188+ if (keep_names(string , pattern )) copy_names(string , out ) else out
196189}
197190
198191like_to_regex <- function (pattern ) {
0 commit comments