how to ignore case in sep argument for tidyr::separate()

Viewed 142

If I want to separate a string into a few new columns based on a letter, how can I ignore the case of that letter? regex("h", ignore_case = TRUE) is not working in tidyr::separate() and the string is not being separated on capital H's. However the regex argument works fine in str_split().

library(dplyr)
library(tidyr)
library(stringr)

tibble(x = "I hear Henry has Heads") %>% 
    separate(
        x, 
        into = c("h1", "h2", "h3"), 
        sep = regex("h", ignore_case = TRUE), 
        extra = "merge"
    )

str_split("I hear Henry has heads", pattern = regex("h", ignore_case = TRUE))
0 Answers
Related