Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you always suppress messages in R?

Tags:

r

The most common place I've seen messages used in R is in the starting of a package. Suppressing one function's worth of messages is easily accomplished with suppressMessages as discussed here: Disable Messages Upon Loading Package in R. It is also possible to suppress multiple lines of message generating function calls by embedding {} inside of the supressMesssages function call. However, if you have a full script with messages happening here and there, is there anyway to disable them completely? I'm looking for something like option(warn=-1) but for messages. Please note that sink doesn't quite do what I want because it redirects all output... I would like to keep output from print but not hold onto output from message.

like image 636
russellpierce Avatar asked Jul 15 '14 20:07

russellpierce


People also ask

How do I suppress a message in R?

The simplest way of handling conditions in R is to simply ignore them: Ignore errors with try() . Ignore warnings with suppressWarnings() . Ignore messages with suppressMessages() .

How do I hide error messages in R?

As suggested by the previous solution, you can use try or tryCatch functions, which will encapsulate the error (more info in Advanced R). However, they will not suppress the error reporting message to stderr by default. This can be achieved by setting their parameters. For try , set silent=TRUE .


1 Answers

Use the type parameter in sink

# Open a file to send messages to
zz <- file("messages.Rout", open = "wt")
# Divert messages to that file
sink(zz, type = "message")
message("not gonna show up in console")
like image 174
Dason Avatar answered Sep 19 '22 10:09

Dason