【发布时间】:2019-09-18 01:52:42
【问题描述】:
我有一个带有多行字符串的 tibble,我想使用 tidyr::extract 使用正则表达式组提取变量,其中值是多行字符串。但是,在以下示例中,我没有提取 - 分隔的组。
library(tidyverse)
df <- tibble(x = "12\n34-56\n78-90\n12")
my_regex <- regex("(.*)-(.*)-(.*)", multiline = TRUE, dotall = TRUE)
extract(df, x, c("y", "z", "a"), my_regex)
#> # A tibble: 1 x 3
#> y z a
#> <chr> <chr> <chr>
#> 1 <NA> <NA> <NA>
正则表达式本身没有问题,如 stringr::str_view 所示。
str_view(df$x, my_regex)
这是 tidyr::extract 的已知错误或功能吗?(请注意,我的实际问题更复杂,不适用于 tidyr::separate 像这样。)
【问题讨论】: