Is there a package like bigmemory in R that can deal with large list objects?

删除回忆录丶 提交于 2019-12-11 04:16:52

问题


I know that the R package bigmemory works great in dealing with large matrices and data frames. However, I was wondering if there is any package or any ways to efficiently work with large list.

Specifically, I created a list with its elements being vectors. I have a for loop and during each iteration, multiple values were appended to a selected element in that list (a vector). At first, it runs fast, but when the iteration is over maybe 10000, it slows down gradually (one iteration takes about a second). I'm going to go through about 70000 to 80000 iterations, and the list would be so large after that.

So I was just wondering if there is something like big.list as the big.matrix in the bigmemory package that could speed up this whole process.

Thanks!


回答1:


I'm not really sure if this a helpful answer, but you can interactively work with lists on disk using the filehash package.

For example here's some code that makes a disk database, assigns a preallocated empty list to the database, then runs a function (getting the current time) that fills the list in the database.

# how many items in the list?
n <- 100000
# setup database on disk
dbCreate("testDB") 
db <- dbInit("testDB")
# preallocate vector in database
db$time <- vector("list", length = n)
# run function using disk object
for(i in 1:n) db$time[[i]] <- Sys.time()

There is hardly any use of RAM during this process, however it is VERY slow (two orders of magnitude slower than doing it in RAM on some of my tests) due to constant disk I/O. So I'm not sure that this method is a good answer to the question of how you can speed up working on big objects.




回答2:


DSL package might help. The DList object works like a drop in replacement for R's list. Futher, it provides a distributed list like facility too.



来源:https://stackoverflow.com/questions/13521344/is-there-a-package-like-bigmemory-in-r-that-can-deal-with-large-list-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!