output_list = lapply(seq_along(input_df), generate_data)
I'm looping through many data frames, and applying my own function generate_data
which returns a list.
Each list is nested within the output_list, but if the loop times out, how can I keep the lists which have been generated so far within output_list?
I've looked into the functions tryCatch()
, withTimeout()
, and memory.limit()
.`
The solution to my problem was to use assign() to assign each list to a new environment:
output_list = lapply(seq_along(input_df),
function (x) {
temp = generate_data(x)
assign(paste0("df_", x), temp, envir = e)
return(temp)
})
Nope. The solution to my problem was to use save() inside the lapply loop:
output_list = lapply(seq_along(input_df),
function (x) {
temp = generate_data(x)
save(temp, file = paste0("DF/df_", x))
return(temp)
})
Saving to disk means I don't lose all my data if the session crashes.