45

I'm trying to run a r script from the command line, but I get warning messages when packages are loaded:

C:\Temp>Rscript myscript.r param
Warning message:
package 'RODBC' was built under R version 3.0.1
Warning message:
package 'ggplot2' was built under R version 3.0.1
Warning message:
package 'reshape2' was built under R version 3.0.1
Warning message:
package 'lubridate' was built under R version 3.0.1
Warning message:
package 'scales' was built under R version 3.0.1

I' tried to use suppressPackageStartupMessages:

suppressPackageStartupMessages(library(RODBC))

or supressMessages

suppressMessages(library(RODBC))

but these did not suppress these messages. How to get rid of these warnings?

jrara
  • 15,427
  • 31
  • 87
  • 119
  • 3
    If you want to get rid of messages the best solution would be to reinstall those packages. They won't work under R >= 3.0 anyway. – zero323 Sep 21 '13 at 09:27
  • 1
    I could not try but `suppressWarnings(library(RODBC))` should work. But I suggest to follow @zero323's advice. – sgibb Sep 21 '13 at 09:39
  • I think you need to update R. Apparently you use a version < 3.0.1. – Roland Sep 21 '13 at 10:22
  • Yes, I use version 3.0.0. But anyways, how can I suppress these messages, when upgrading is currently not possible? – jrara Sep 21 '13 at 10:30

3 Answers3

64

These are not messages but warnings. You can do:

suppressWarnings(library(RODBC))

or

suppressWarnings(suppressMessages(library(RODBC)))

to suppress both types.

Ben
  • 40,397
  • 18
  • 126
  • 218
flodel
  • 85,263
  • 19
  • 176
  • 215
25

I put this at the top of all my scripts and preface my library loads with it:

shhh <- suppressPackageStartupMessages # It's a library, so shhh!

Then you can load the library thusly:

shhh(library(tidyverse))

and rely on perfect silence.

Greenleaf
  • 447
  • 4
  • 11
0

You can use:

options(warn=-1)

to get back to normal:

options(warn=0)
dare_devils
  • 1,575
  • 1
  • 13
  • 15