coolscitist
coolscitist

Reputation: 3377

R - suppressMessages / suppressWarnings not working

I have tried expressions with suppressMessages(expr), suppressWarnings(expr), but they keep outputting messages.

eg:

suppressWarnings(ksvm(y~., data=data, type='C-svc', cross=5, kernel=kernel))

keeps generating this message.

Setting default kernel parameters

How do I suppress messages from libraries? Is there a way to do this globally?

Have tried:

{r messages=FALSE, warnings=FALSE}

Upvotes: 4

Views: 15197

Answers (3)

Michael Kuehn
Michael Kuehn

Reputation: 21

You can pass an empty list to the kpar argument.

Like ksvm(y~., data=data, type='C-svc', cross=5, kernel=kernel, kpar = list())

Upvotes: 2

Karolis Koncevičius
Karolis Koncevičius

Reputation: 9656

Here is the link to the line where the output is generated: https://github.com/cran/kernlab/blob/master/R/ksvm.R#L88

Looking at that we see that the message is displayed with cat() not with message(). suppressMessages() does not suppress the cat output.

There are multiple ways to get rid of the cat output. One is to capture the message and then hide it like so:

invisible(capture.output(ksvm(...)))

Upvotes: 12

C. Braun
C. Braun

Reputation: 5201

If it does not say that it is a warning, you should use suppressMessages. Try putting the function call in braces:

suppressMessages({ksvm(y~., data=data, type='C-svc', cross=5, kernel=kernel)})

Upvotes: 4

Related Questions