简体   繁体   中英

foreach (R): suppress Messages from packages loaded from global environment

I am loading several packages loaded in the global environment in my foreach call using .packages = (.packages()) . However, I could not find how to suppress the package startup messages. As they are loaded for every assigned core, this list gets rather long. I already tried wrapping the standard calls like suppressMessages() etc. around the function call and the .packages argument without success.

foreach(i = x, .packages = (.packages()))

I am using the foreach call within a generic function so it needs to adapt to whatever packages are loaded a priori by the user. I could just use an apply call inside the foreach call with all the packages loaded in the global environment but I assume foreach needs it to be loaded in its .packages argument?

If there is a better way in general how to do this, let me know.

I have a lame semi-answer: when you create the cluster you can specify outfile = '/dev/null' to silence all output from worker nodes. The problem is, this prevents you from printing anything else from your nodes...

As a workaround, I am silencing nodes as described, but using a progress bar to give the user at least some information, though undetailed.

This is also a lame answer and more of a work around. If your function is in a separate R script instead of using .packages() you do:

    options( warn = FALSE )
    suppressPackageStartupMessages( library(dplyr) )
    options( warn = FALSE )

inside of your your function file when you call your libraries. This will shutdown the warnings for your packages and turn them back on after. It would be great if there was an option for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM