I have a package that has a bunch of functions that generate ggplot2 objects. Recently, ggplot2 added an update that gives a message that says:
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
I know why ggplot2 is saying that, but I don't need to hear it every time I run a plot (and it confuses my users because they think they did something wrong). I know I can suppress the messages by wrapping a print statement in suppressMessages
but I don't want to print
a plot, I want to return
it. If I print
it, it will display the plot, even when I don't want to display it.
Any ideas? Here's a minimum working example.
f = function(y,x,data){
p = ggplot(data, aes_string(x,y)) + geom_point() + geom_smooth(se=F)
#suppressMessages(return(p)) ### doesn't work
suppressMessages(print(p)) ### works, but I don't want to PRINT it
}
data(iris)
head(iris)
f("Sepal.Length", "Sepal.Width", iris)