如何累积readr::read\u lines\u chunked的结果?
我以以下方式使用如何累积readr::read\u lines\u chunked的结果?,r,readr,R,Readr,我以以下方式使用readr::read\u lines\u 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
readr::read\u lines\u 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))
}
})
if(!require(readr))install.packages(“readr”,repos=”http://cran.us.r-project.org")
mytb我找到了解决办法。这个包有一组包装自定义处理程序的回调处理程序。这就是它的工作原理:
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)
}))
mytb变量名在这里很难理解-回调函数中的两个参数是xml
和pos
,但是您不使用它们,并且tmp
在使用之前没有声明。