Saving R Baseplots As Objects & Plotting Those Objects #16
-
DescriptionI am facing issues while trying to plot R base plots which are saved as targets objects. However, I am able to plot ggplot plots which are saved as targets objects, without any issues. Please help me with this. Thank you. Reproducible exampleBelow code goes in functions.R fileDefine a function to create & return a R baseplot (boxplot in this case) Below code goes in _targets.R fileCreate targets objects based on the above two functions Verifying the targets objects
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A base plot is not an object in the R session, it lives in a graphics device of the current R session. You could save the plot to a file and track it with # _targets.R file
library(targets)
save_plot <- function(path) {
png(path)
plot(mpg ~ cyl, data = mtcars)
dev.off()
path
}
list(
tar_target(plot, save_plot("plot.png"), format = "file")
) |
Beta Was this translation helpful? Give feedback.
A base plot is not an object in the R session, it lives in a graphics device of the current R session. You could save the plot to a file and track it with
format = "file"
: