问题
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