unleash R potential

Hello, I'm running a quite energy-intensive code that would run for 6 hours if it goes at his current pace.
When looking at the task manager I remark that R isn't using all the resources to get there as fast as possible.
How can I get R to unleash his full potential ?

It is basically impossible to tell you what to do without seeing all your code. There might be several points at which we can optimize it. The for loops I can see in your code already can probably be replaced by apply family and then there might be other ways to introduce parallelization.


Sorry my question is not about the code himself but rather about how to boost R to execute a code faster. I will try to use apply() to be faster but I still want to know if I can get an application to use all the capacities of the computer.

It in fact is about the code. How you write the code determines how well it will be executed and how fast it will run. There are several ways in which you can instruct R to do the same task but the difference in time between approaches can be 100 or 10 000 times slower.

In terms of resources look at: Performance · Advanced R. and Fast R code


Thank you a lot for this resources !
I might do a good reprex later to maybe use a apply()/sapply() structure, the data are complex and the code too

1 Like

You could check out the future package, for instance, but providing a repex would be the best for now...

1 Like

I use the parallel library.
Once you have put the repetitive bits which are in loops into a function suitable for lapply or sapply, the parLapply/parSapply functions (or the -LB versions) are your friend.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.