0

When I require a library, I don't want all the extra output that goes with it. How can I turn this off?

Has output (bad):

> require('forecast')
Loading required package: forecast
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: timeDate
This is forecast 5.4 
>

Doesn't have output (good):

> require('forecast')
>
Don P
  • 60,113
  • 114
  • 300
  • 432
  • `?library` tells you to use `suppressPackageStartupMessages`. What's wrong with that? – Joshua Ulrich Aug 09 '14 at 14:40
  • @JoshuaUlrich - further down it says, regarding `suppressPackageStartupMessages`, *this will suppress all messages from R itself but not necessarily all those from package authors.* – Rich Scriven Aug 09 '14 at 17:15
  • @RichardScriven: that's because package authors may use something other than `message` when their package is loaded, in which case your solution wouldn't suppress them either. `suppressPackageStartupMessages` works fine in the OP's example. – Joshua Ulrich Aug 09 '14 at 17:37

1 Answers1

3

You can wrap require (and/or library) with suppressMessages ,

suppressMessages(require(forecast))

and the messages won't appear when loading.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245