【问题标题】:Why does tidyr extract not respect the ignore_case flag? [duplicate]为什么 tidyr extract 不尊重 ignore_case 标志? [复制]
【发布时间】:2019-11-03 11:05:24
【问题描述】:

我希望我可以将 regex 传递给 tidyr 的 extract 并将 ignore_case 设置为 true。但它显然不起作用:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = regex("(value)", ignore_case = TRUE)
)

这应该会产生一列result 和一行值Value 的小标题。但它没有,单元格是NA

使用大写字母时,代码相同:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = regex("(Value)", ignore_case = TRUE)
)

ignore_case = TRUEignore.case = TRUE 直接作为参数传递给extract 并不能解决问题。

【问题讨论】:

  • 不知道发生了什么,但regex = regex("(?i)(value)") 有效。
  • regex 函数来自不同的包 stringr。我没有深入研究代码,但很可能 tidyr 函数根本不是为了使用另一个包中的特殊函数而编写的。
  • 可以查看与本帖相关的github issuegithub.com/tidyverse/tidyr/issues/223

标签: r regex extract tidyverse tidyr


【解决方案1】:

谢谢wiktor,确实有效:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = "(?i)(value)"
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 2022-10-08
    • 2021-05-24
    • 2013-10-17
    • 2015-03-14
    • 2021-02-27
    • 1970-01-01
    相关资源
    最近更新 更多