7

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!

cacti5
  • 2,006
  • 2
  • 25
  • 33
Adam Price
  • 810
  • 2
  • 11
  • 21
  • 3
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 13 '18 at 19:26
  • This is a duplicate questions of about how to supress messages. Shame that Benjamin posted the answer beforehand. – InfiniteFlash Feb 13 '18 at 19:28
  • 1
    Possible duplicate of [Converting specific cells of data frame to table in R](https://stackoverflow.com/questions/34066576/converting-specific-cells-of-data-frame-to-table-in-r) – Eric Fail Feb 13 '18 at 19:29
  • 7
    in this case use `id.vars=NULL` – user20650 Feb 13 '18 at 19:30
  • 2
    I would argue that while that issue is covered in that topic, that it isn't obvious from the title of the question in that post. I did search for things like how to hide messages from melt and the specific message output, but didn't find anything so asked directly. I think this post will be better indexed for people like me in the future who are looking for how to do this specifically. – Adam Price Feb 13 '18 at 19:32
  • I'm looking for a duplicate to tag now, and will gladly delete my answer when I find one. I'm not sure the question tagged by @EricFail addresses the question directly. – Benjamin Feb 13 '18 at 19:34
  • Sorry if it's a duplicate, again I did try to find this before posting but wasn't able to. At any rate, thanks for your answer @Benjamin , it's exactly what I was looking for. – Adam Price Feb 13 '18 at 19:35
  • 3
    imo the better answer is @user20650's. That is the correct way to use melt, since in some cases, melt will automatically pick an ID variable. – alan ocallaghan Feb 13 '18 at 19:38
  • 1
    You don't need to apologize for posting a duplicate. It happens. Sometimes it takes a while to figure out the right search terms to get what you're looking for. The duplicate issue is something the more seasoned users take up to help optimize future search performance. And note specifically that the duplicate issue was in no way a criticism of you or your question, but of me for answering before looking for the duplicate. – Benjamin Feb 13 '18 at 19:38
  • I am happy to have learned both ways of doing this. Thanks to @user20650 as well! – Adam Price Feb 13 '18 at 19:40
  • Possible duplicate of [lubridate - messages ](https://stackoverflow.com/questions/9168684/lubridate-messages) – Benjamin Feb 13 '18 at 19:40
  • 1
    @user20650 Sure, I am happy to do that. – Adam Price Feb 13 '18 at 21:00

1 Answers1

12

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)

Benjamin
  • 16,897
  • 6
  • 45
  • 65
  • Can anyone explain more how to do this? I filled in: suppressMessages({ reshape2::melt(id.vars = NULL)) }) but it doesn't work – B.Quaink Jul 27 '20 at 16:57