R中的stri_detect_regex错误 [英] Error in stri_detect_regex in R

查看:106
本文介绍了R中的stri_detect_regex错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误


stri_detect_regex中的错误(字符串,模式,opts_regex = opts(pattern)):
正则表达式模式中嵌套的括号不正确。 (U_REGEX_MISMATCHED_PAREN)

Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) : Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)

运行代码时

  # find occurrences of initial dataframe
  named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})

其中 named_RN $ V1 看起来像

aldosterone
renin
potassium
calcitrol

final_RN $ named_RN 看起来

aldosterone, creatinine 
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol

我的代码旨在在 named_RN 内创建一个新变量,该变量显示每个短语的原始计数,因此 named_RN 看起来像

and my code aims to create a new variable within named_RN that shows the raw counts of each phrase, so that named_RN looks like

V1              search
aldosterone     1
renin           0
potassium       0
calcitrol       2

P租赁咨询。谢谢。

推荐答案

由于使用的是固定字符串而不是正则表达式,因此需要告诉正则表达式引擎将模式用作纯文字文本。可以这样使用它:

Since you are using fixed strings, not regular expressions, you need to tell the regex engine to use the patterns as plain, literal text. You can use it like this:

str_detect(final_RN$named_RN, fixed(x))
                              ^^^^^^^^

请参见 固定匹配项


fixed(x)仅匹配 x 。这是一个非常有限的模式,但是这种限制可以使匹配更快。

fixed(x) only matches the exact sequence of bytes specified by x. This is a very limited "pattern", but the restriction can make matching much faster.

您还可以考虑 coll(x),以便在执行不区分大小写的搜索时要使用人工语言排序规则。

You might also consider coll(x) in case you want to use human-language collation rules while performing a case insensitive search.

这篇关于R中的stri_detect_regex错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆