8

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.

pat-s
  • 5,992
  • 1
  • 32
  • 60
  • Why does [this](http://stackoverflow.com/questions/8681688/disable-messages-upon-loading-package-in-r) not help? – Christoph Aug 28 '16 at 09:37
  • I assume its because I do not have a direct call to `library()` here but the packages are loaded with the `.packages` argument. – pat-s Aug 28 '16 at 09:50
  • In the docs of .packages they write `.packages returns information about package availability.` If you want to load a package, why don't you use `require` or `library`? – Christoph Aug 28 '16 at 10:06
  • The `(.packages())` call returns all packages loaded in the global environment. These packages should explicitly be loaded by `foreach` again for every assigned core to avoid problems during the function call using the `.packages` argument. Hence, there is no direct `library()`call. Packages vary among function usage and are not fixed, hence they need to be loaded interactively. – pat-s Aug 28 '16 at 10:14

2 Answers2

0

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.

kjohnsen
  • 360
  • 5
  • 15
0

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.

SKyJim
  • 111
  • 7