I have run into what appears to be a fundamental R problem (bug?).
The problem is I am participating in R package development and there is a pretty sophisticated function. When I run this function it leaves a lot of garbage in memory, which is only partially cleared by gc(). As a result when I want to run this function within a loop what happens is in the 2nd-3rd iteration, R consumes 12-16gb and stops working due to insufficient memory.
This problem is Windows-specific since my collaborators cannot reproduce it under LINUX. Hence my question is this: can I perform an R restart within a loop.
I understand this will remove all the variables, but that's what I need.
E.g. a good solution will be to write a script that calls out R session, executes the function and then closes R session.