SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: Use of mcapply in partykit::varimp.cforest [ Reply ]
By: Achim Zeileis on 2026-05-27 07:47
[forum:50163]
You're very welcome. Thanks for the feedback, much appreciated!

RE: Use of mcapply in partykit::varimp.cforest [ Reply ]
By: Andrew Psoras on 2026-05-26 16:23
[forum:50162]
It certainly does help - I should have noticed that possibility as I was poking around in the function itself. Thank you for the prompt reply and for your work on partykit!

RE: Use of mcapply in partykit::varimp.cforest [ Reply ]
By: Achim Zeileis on 2026-05-22 01:09
[forum:50161]
Andrew, thanks for the suggestion. The "cores" argument is just a convenience option to make using mclapply() a little bit easier.

Any other type of parallelization can be used by setting up your desired "applyfun" directly. You can also use this for plugging in mirai. I have never used this myself but judging from your code something similar to the following should probably work. Say you want to use 4 cores:

mirai_apply <- function(X, FUN, ...) {
mirai::daemons(4)
res <- mirai::collect_mirai(mirai::mirai_map(X, FUN, ...))
mirai::daemons(0)
return(res)
}
varimp(cf_object, conditional = TRUE, applyfun = mirai_apply)

Hope that helps,
Achim

Use of mcapply in partykit::varimp.cforest [ Reply ]
By: Andrew Psoras on 2026-05-21 18:11
[forum:50160]

varimp.R (2) downloads
Greetings,

I hope this is the correct place for this suggestion!

As you very likely know, mcapply does not support parallelization on windows, and is invoked with the "cores" argument of varimp.cforest.

Mirai (https://mirai.r-lib.org/index.html a slightly newer, parallel backend for R) is cross-platform and is easy to drop in to functions like this.

For large CRFs and "conditional = TRUE" parallelization is incredibly important for getting results within n minutes rather than n hours.

I have attached my changed version of partykit/r/varimp.R as a working demonstration (changes only in varimp.cforest.

The only structural change was to add the call to close mirai process daemons after the processing is done. They are persistent and reused in between iterations (making parallelization less expensive on windows with respect starting/stopping many processes relative to mcapply/unix forks).

Please let me know what you think!

Thank you,
Andrew

Thanks to:
Vienna University of Economics and Business Powered By FusionForge