一起使用 LaF 和 grepl

Use LaF and grepl together

我想读入一个可能很大的文本文件并根据正则表达式动态过滤相关行。我的第一种方法是使用支持分块读取的包 LaF,然后使用 grepl 进行过滤。但是,这似乎不起作用:

library(LaF)
fh <- laf_open_csv("myfile.txt", column_types="string", sep="°") 
# would be nice to declare *no* separator
fh[grepl("abc", fh[[1]]), ]

returns as.character.default(x) 中的错误 -- 无法将此 S4 转换为字符。似乎 grepl 应用于 S4 函数而不是块。

有没有一种从大文件中读取文本行并有选择地过滤它们的好方法?

好的,我刚发现 process_blocks:

regfilter <- function(df, result) c(result, df[grepl("1745", df[[1]]),1])
process_blocks(fh, regfilter)

这行得通,现在我只需要找到一种忽略分隔符的方法..