Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In R, using melt(), how can I hide warning messages?

Tags:

r

melt

reshape2

I'm melting some data and don't want to provide an id.var parameter to melt. The data melts fine, but I get the

"No id variables; using all as measure variables"

Is there a way to prevent that message from coming up, or a way to say id.var=default or something like that? An iris example using dplyr:

> dt <- iris %>% summarize_at(c("Sepal.Length","Sepal.Width"), funs(mean))
> dt
  Sepal.Length Sepal.Width
1     5.843333    3.057333
> melt(dt, value.name="Mean")
No id variables; using all as measure variables
      variable     Mean
1 Sepal.Length 5.843333
2  Sepal.Width 3.057333

Alternatively is there a way to tell a function to not print warning messages or something like that? Thanks!

like image 585
Adam Price Avatar asked Feb 13 '18 19:02

Adam Price


1 Answers

Strictly speaking, this is a message, not a warning. (see ?message and ?warning). You can suppress messages with suppressMessages

suppressMessages({
  reshape2::melt(head(mtcars))
})

For melt specifically, you may use id.vars = NULL. (with credit to @user20650)

like image 56
Benjamin Avatar answered Oct 08 '22 08:10

Benjamin