I am working with the R programming language.
Normally, I print iterations from loops - this helps me keep track of things. For example:
my_list = list()
for (i in 1:1000)
{
{tryCatch({
frame_i = rnorm(1,1,1)
my_list[[i]] = frame_i
ifelse(i%% 10 == 0 , cat("\f"), print(i))
}, error = function(e){})
}}
# desired output
[1] 1.0000000 -0.9298258
Now, I am trying to do the same thing - but using the "doParallel" libraries in R:
library(doParallel)
registerDoParallel(cl <- makeCluster(3))
test = foreach(i = 1:1000, .combine = "rbind") %dopar% {
{tryCatch({
frame_i = rnorm(1,1,1)
my_list[[i]] = frame_i
ifelse(i%% 10 == 0 , cat("\f"), print(i))
}, error = function(e){})
}}
This loop seems to have run, but nothing seems to be printing.
I tried consulting the following posts:
- Print outputs in foreach loop in R (e.g. sink("Report.txt") does not appear to create a file on my computer)
- No standard output received inside foreach loop
- R foreach and print behavior
- Is it possible to create a text log within a foreach() %dopar% call in R?
But I still can't seem to figure out how to print the (intermittent) results from the "foreach loop" - can someone please help me figure out how to do this?
Thanks!
- Note: I am interested in printing out the actual iterations, and not creating a progress bar