goollan
goollan

Reputation: 785

How do I suppress warnings with plotly?

I'd like to stop warnings in plotly without turning off warnings globally

This code is going into a function so it could be run in a different session

This is my code

      fit <-
        plot_ly(credit_old, 
            y = ~score, 
            color = ~fte, 
            type = "box")
      suppressWarnings(fit)   

I still get

Warning messages:
1: In RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

2: In RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Upvotes: 2

Views: 2294

Answers (1)

Paul
Paul

Reputation: 9087

suppressWarnings(fit) returns a value which is fit. This result then gets auto-printed which is why the warning is shown. It is similar to this

result <- suppressWarnings(fit) # No warning here
print(result) # Warning here
#> Warning messages:
#> 1: In min(x, na.rm = na.rm) :
#>   no non-missing arguments to min; returning Inf
#> 2: In max(x, na.rm = na.rm) :
#>   no non-missing arguments to max; returning -Inf

You can call print inside suppressWarnings. This doesn't result in auto-printing because print returns it's value invisibly.

suppressWarnings(print(fit))

Upvotes: 3

Related Questions