Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warning messages from cast()

Tags:

r

reshape

I use cast() from the reshape package quite frequently. Almost every time, this warning pops up:

Aggregation requires fun.aggregate: length used as default

I've tried to set options( warn =-1), to no avail. How does one suppress these warnings?

like image 591
Brandon Bertelsen Avatar asked Jun 18 '12 03:06

Brandon Bertelsen


2 Answers

You could manually specify fun.aggregate to be length.

cast(your_inputs_to_cast, fun.aggregate = length)
like image 102
Dason Avatar answered Nov 09 '22 01:11

Dason


Aggregation requires fun.aggregate: length used as default

is message not a warning - letting you know that the function as decided something for you. I think the best option is @Dason's answer - i.e. to manually specify this option.

However, If you don't want to do that:

You can suppress messages by wrapping the function in suppressMessages

Using the example from cast

names(ChickWeight) <- tolower(names(ChickWeight))
chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE)

suppressMessages(cast(chick_m, time ~ variable))

Or you could create your own function

cast_suppress <- function(...){suppressMessages(cast(...))}
cast_suppress(chick_m, time ~ variable)
like image 40
mnel Avatar answered Nov 09 '22 01:11

mnel