law*_*yeR 4 regex runtime-error r gsub stringr
假设使用管道分隔符“ firm.pat”将900多个公司名称粘贴在一起以形成正则表达式模式。
firm.pat <- str_c(firms$firm, collapse = "|")
Run Code Online (Sandbox Code Playgroud)
对于一个名为“ bio”的数据框,该数据框具有大的字符变量(每250行包含100多个单词),名为“注释”,我想用空格替换所有公司名称。既有gsub呼叫和str_replace_all呼叫返回相同的神秘的错误。
bio$comment <- gsub(pattern = firm.pat, x = bio$comment, replacement = "")
Error in gsub(pattern = firm.pat, x = bio$comment, replacement = "") :
assertion 'tree->num_tags == num_tags' failed in executing regexp: file 'tre-compile.c', line 634
library(stringr)
bio$comment <- str_replace_all(bio$comment, firm.pat, "")
Error: assertion 'tree->num_tags == num_tags' failed in executing regexp: file 'tre-compile.c', line 634
Run Code Online (Sandbox Code Playgroud)
traceback() 没有启发我。
> traceback()
4: gsub("aaronson rappaport|adams reese|adelson testan|adler pollock|ahlers cooney|ahmuty demers|akerman|akin gump|allen kopet|allen matkins|alston bird|alston hunt|alvarado smith|anderson kill|andrews kurth|archer
# hundreds of lines of company names omitted here
lties in all 50 states and washington, dc. results are compiled through a peer-review survey in which thousands of lawyers in the u.s. confidentially evaluate their professional peers."
), fixed = FALSE, ignore.case = FALSE, perl = FALSE)
3: do.call(f, compact(args))
2: re_call("gsub", string, pattern, replacement)
1: str_replace_all(bio$comment, firm.pat, "")
Run Code Online (Sandbox Code Playgroud)
其他三篇文章提到了SO上的隐式错误,一个传递的引用,并引用了另外两个倾斜的引用,但没有讨论。
我知道这个问题缺少可复制的代码,但是即使如此,我如何找出错误的解释?更好的是,如何避免引发错误?数量较少的公司似乎不会出现该错误,但是我无法检测到模式或阈值。我正在运行Windows 8,RStudio和每个软件包的更新版本。
谢谢。
我遇到了由数百个制造商名称组成的模式的相同问题。我可以建议该模式过长,因此我将其分为两个或多个模式,并且效果很好。
ml<-length(firms$firm)
xyz<-gsub(sprintf("(*UCP)\\b(%s)\\b", paste(head(firms$firm,n=ml/2), collapse = "|")), "", bio$comment, perl=TRUE)
xyz<-gsub(sprintf("(*UCP)\\b(%s)\\b", paste(tail(firms$firm,n=ml/2), collapse = "|")), "", xyz, perl=TRUE)
Run Code Online (Sandbox Code Playgroud)