我通过以下方式使用readr::read_lines_chunked:
if(!require(readr)) install.packages("readr", repos = "http://cran.us.r-project.org")
mytb <- NULL
read_lines_chunked(file="/tmp/huge.xml", chunk_size=10, callback = function(xml, pos) {
// extract values from xml into tmp
if (is.null(mytb)) {
users <- as_tibble(tmp)
} else {
users <- bind_rows(users, as_tibble(tmp))
}
})但这不起作用,因为mytb总是以null的身份结束...如何将结果累积到tibble中?
发布于 2019-12-13 08:44:19
我找到了解决方案。此包具有一组包装自定义处理程序的回调处理程序。这就是它的工作原理:
mytb <- read_lines_chunked(file="/tmp/huge.xml", chunk_size=10, callback = DataFrameCallback$new(function(xml, pos) {
// extract values from xml into tmp
as_tibble(tmp)
}))注意tibble装饰器,并返回我想作为rbind拼接在一起的DataFrameCallback$new(...)。
https://stackoverflow.com/questions/59314478
复制相似问题