![](/img/trans.png)
[英]R: Error in browseURL(x, …) : 'url' must be a non-empty character string
[英]“ 'pattern' must be a non-empty character string” error with agrep in R
我收到以下错误:
'pattern' must be a non-empty character string
尝试运行以下命令时:
rapply(as.list(Database1), function(x) agrep(x,Database2, max.distance=c(cost=1), value=T))
大型数据库
> length(Database1)
[1] 15876500
> length(Database2)
[1] 605
但是当我和小家伙一起跑的时候
> length(Database1)
[1] 29
> length(Database2)
[1] 8
我知道我应该放置可重现的代码,以便数据库只是可以使用以下命令生成的15-25个随机字母的字符串:
Database1<- unlist(replicate(n, paste0(sample(LETTERS, m), collapse="")))
其中“ n”是长度,“ m”是15-25之间的整数。
好吧,我可以通过向模式提供""
来获得该错误消息。 如此处所示,但没有其他潜在的不良模式:
agrep("", "hello")
agrep(" ", "hello")
agrep(NA, "hello")
agrep(NULL, "hello")
## > agrep("", "hello")
## Error in agrep("", "hello") :
## 'pattern' must be a non-empty character string
## > agrep(" ", "hello")
## [1] 1
## > agrep(NA, "hello")
## [1] NA
## > agrep(NULL, "hello")
## Error in agrep(NULL, "hello") : invalid 'pattern' argument
因此,我猜您在数据库中有一个""
。 要检查使用情况:
which(Database1 == "")
编辑 :
采用:
rapply(as.list(Database1), function(x) {
try(agrep(x,Database2, max.distance=c(cost=1), value=T))
)
这将告诉您错误在哪里,然后您可以继续研究该元素并找出导致该错误的原因。 我会尝试数据的多个子集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.