0

我收到以下错误:

'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 之间的整数。

4

1 回答 1

3

""好吧,我可以通过提供给模式来获得该错误消息。如此处所示,但没有其他潜在的不良模式:

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

所以我猜你有一个""in Database`。检查使用:

which(Database1 == "")

编辑

利用:

rapply(as.list(Database1), function(x) {
    try(agrep(x,Database2, max.distance=c(cost=1), value=T))
)

这将告诉您错误在哪里,然后您可以深入了解该元素并找出导致它的原因。我会尝试数据的多个子集。

于 2014-02-20T00:08:17.817 回答