I wrote a simple plotting routine.
x <- c(1,2,3,4)
output_file <- "test_plot.png"
png(output_file, units="cm", width = 12, height = 20, res=300)
plot(x, c(2,2,2,2))
dev.off() # <- plot is saved to disk
Now I moved the routine into a function. When I call the function, no error is thrown but the plot is not save to disk. Why is this the case and how can I circumvent it?
create_plot <- function(x, output_file){
png(output_file, units="cm", width = 12, height = 20, res=300)
plot(x, c(2,2,2,2))
dev.off()
}
create_plot(x, output_file) # <- plot is not saved to disk?