How do I suppress warnings with plotly?

余生长醉 提交于 2021-02-07 10:12:26

问题


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

回答1:


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))


来源:https://stackoverflow.com/questions/64525470/how-do-i-suppress-warnings-with-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!