Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warning messages when loading a library?

Tags:

r

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?

like image 208
jrara Avatar asked Sep 21 '13 09:09

jrara


People also ask

How do I suppress Library messages in R?

suppressPackageStartupMessages() method in R language can be used to disable messages displayed upon loading a package in R. This method is used to suppress package startup messages. The package should be pre-installed in R, otherwise, a warning is displayed upon function call.


2 Answers

These are not messages but warnings. You can do:

suppressWarnings(library(RODBC))

or

suppressWarnings(suppressMessages(library(RODBC)))

to suppress both types.

like image 71
flodel Avatar answered Oct 20 '22 08:10

flodel


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.

like image 27
Greenleaf Avatar answered Oct 20 '22 07:10

Greenleaf