stri_locate, stri_match, stri_extract: If there are no matches, return a 0-row matrix #117

Closed
hadley opened this Issue Nov 26, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@hadley

hadley commented Nov 26, 2014

I think this is more consistent: 2 matches = 2 rows, 1 match = 1 row, 0 matches = 0 rows:

stringi::stri_locate_all("aab", fixed = "a")[[1]]
stringi::stri_locate_all("aab", fixed = "b")[[1]]
stringi::stri_locate_all("aab", fixed = "c")[[1]]
@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Nov 26, 2014

Similarly for stri_match_first(): you should have zero row for zero matches (not 1 row full of NA)

hadley commented Nov 26, 2014

Similarly for stri_match_first(): you should have zero row for zero matches (not 1 row full of NA)

@gagolews

This comment has been minimized.

Show comment
Hide comment
@gagolews

gagolews Nov 26, 2014

Owner

Related discussion == #75

OK, I'll again introduce a new argument, omit_no_match or something. That's the most transparent solution, IMO, here.

Owner

gagolews commented Nov 26, 2014

Related discussion == #75

OK, I'll again introduce a new argument, omit_no_match or something. That's the most transparent solution, IMO, here.

@gagolews gagolews changed the title from If there are no matches, stri_locate_all return a 0-row matrix to stri_locate, stri_match: If there are no matches, return a 0-row matrix Nov 26, 2014

@gagolews gagolews changed the title from stri_locate, stri_match: If there are no matches, return a 0-row matrix to stri_locate, stri_match, stri_extract: If there are no matches, return a 0-row matrix Nov 26, 2014

@gagolews gagolews added this to the stringi-0.4 milestone Nov 26, 2014

@gagolews gagolews self-assigned this Nov 26, 2014

@gagolews

This comment has been minimized.

Show comment
Hide comment
@gagolews

gagolews Nov 26, 2014

Owner

BTW, I like the default behavior (omit_na_match=FALSE, as it is quite consistent with stri_extract_first => no match == NA) and I can easily test whether the result is not interesting for me (=> is.na(output[[i]][1]) vs length(output[[i]][1]) > 0 && !is.na(output[[i]][1]))

Anyway, the requested arg will soon be available. :)

Owner

gagolews commented Nov 26, 2014

BTW, I like the default behavior (omit_na_match=FALSE, as it is quite consistent with stri_extract_first => no match == NA) and I can easily test whether the result is not interesting for me (=> is.na(output[[i]][1]) vs length(output[[i]][1]) > 0 && !is.na(output[[i]][1]))

Anyway, the requested arg will soon be available. :)

gagolews added a commit that referenced this issue Nov 26, 2014

@gagolews gagolews closed this Nov 26, 2014

@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Nov 27, 2014

Yeah, there's clearly two possible definitions of consistency here. Thanks for the fix!

hadley commented Nov 27, 2014

Yeah, there's clearly two possible definitions of consistency here. Thanks for the fix!

@gagolews gagolews reopened this Nov 27, 2014

@gagolews gagolews closed this Nov 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment