简体   繁体   中英

How to save multiple lists of dataframes and limit number of list elements that can be saved?

I have multiple lists with varying number of elements in each list as in screenshot.

在此处输入图像描述

My current code allows user to save one list at a time. But I am curious if there is a way I can allow user to save all the lists at once.

Additionally (if possible) I want to limit the number of list elements that can be downloaded at once. Lets say for a dataset, list contains 64 elements, but I want user to be able to download only 15 files at a time.

Current code goes like this:

saveFiles <- Function(list){
sapply(names(list), function(x) write.table(list[[x]], file= paste(x,".txt"), sep= "\t", quote=F))
}

Any advice how can this be resolved.

I am not sure I understand your question. is this any good?

library(tictoc) #measure time difference
library(doParallel)

LIST<-lapply(1:150, function(X) X) #create data
names(LIST)<-1:150

doParallel::registerDoParallel(5)
# run in parallel 
tic()
foreach(list=LIST) %dopar% {
  write.table(LIST[[list]], file= paste(list,".txt"), sep= "\t", quote=F)
}
toc()

# regular loop
tic()
for(list in LIST) {
  write.table(LIST[[list]], file= paste(list,".txt"), sep= "\t", quote=F)
}
toc()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM