I'm not sure why you are doing this, presumably you wish to call plot
only for some side effect. Usually this would be the case if you are interested in getting a return value from the plot function, for example using boxplot
to calculate the statistics.
With some plot methods, there is an argument plot = FALSE
you can use. for example with boxplots you can specify boxplot(..., plot = FALSE)
.
But this does not work with the basic plot function. Other options are to use a different plotting library, such as lattice or ggplot, that allow you to assign a plot to an object, rather than draw it. But if you really need to do this with base plot, then the only way I can think of is to send the output to a device other than your screen. For example, to send the output to a temporary .png file and then delete the file, you can do
some_func <- function() {
png("temp.xyz")
a=plot(1:10, )
dev.off()
file.remove("temp.xyz")
return(invisible(10))
}
my_value <- some_func()