extract fails on empty data.frame #313
Closed
Labels
Comments
I am having the same problem. reproducable example using df <- data.frame(col1 = c("q123", "abc"))
tidyr::extract(df, col1, into = "col2", regex = "[0-9]+", remove = FALSE)
#> Error in names(l) <- enc2utf8(into): 'names' attribute [1] must be the same length as the vector [0] When I choose "rerun with Debug", the error is in I am also running |
More minimal reprex: df <- data.frame(x = c("q123", "abc"))
extract(df, x, "y", regex = ".") I think the problem is that there's no grouping defined in the regular expression and the error message doesn't help you discover that. |
Ok, there were actually two problems here. It looks like the motivating issue is actually a small stringi bug; so I'll file over there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproducible example using tidyr 0.6.3.9000:
Expected behaviour: should return an empty data.frame with a new empty column "col2".
Actual behaviour: fails with error:
Error in names(l) <- enc2utf8(into) : 'names' attribute [1] must be the same length as the vector [0]
Why it should be fixed: this makes an otherwise valid pipeline fail when the result of a filter happens to be empty. This requires boiler-plate to guard against empty data when programming with
extract
.The text was updated successfully, but these errors were encountered: