readtext我有一个使用库读入软件的文本列表。
files <-readtext(paste0(wd), "/r/*.pdf", ignore_missing_files = FALSE, text_field = "texts")
这 100 个 pdf 文件大小不等,从 6000 到 40000 字不等。我需要以越来越多的方式将它们分块。
files.ch <- as.character(files$text)
library(stringi)
chunking <- function(c){
words.split <- str_split(c, pattern = boundary(type = "word"))
chunked <- sapply(seq(1000, length(words.split[[1]]), 1000), lapply, function(x) paste(words.split[[1]][1:x], collapse = " "))
return(chunked)
}
chunked <- lapply(files.ch, chunking)
Error in seq.default(1000, length(words.split[[1]]), 1000) :
wrong sign in 'by' argument
这里的by参数-length(words.split[[1]]-似乎有问题。因为文本大小不相等,一个文本的长度不适用于更长的文本。所以,我需要调试这以便函数运行。我by的列表中的所有属性都不能有一个固定值。我需要这个函数by根据进入函数的属性的索引来更改值。我的意思是长度(words.split [ [1]]) 为列表中的第一个,length(words.split[[2]] 为第二个等等。提前感谢您的时间和帮助。