I want to write function which returns a graph but it should not plot the graph. It should only plot the graph when I ask it to.
Here is a MWE.
graph_functions <- function(x) {
plot(1:length(x), x)
points(1:length(x), x^2)
t <- recordPlot()
return(t)
}
answer <- graph_functions(1:10)
library(cowplot)
plot_grid(answer, answer)
In the above code I do not want it to plot the graph when I first compute the answer by calling graph_functions(1:10)
. I only want it to plot the graph when I use plot_grid()
.