Skip to content

Saving R Baseplots As Objects & Plotting Those Objects #16

Answered by wlandau
Sreenath1986 asked this question in Q&A
Discussion options

You must be logged in to vote

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":

# _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")
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Sreenath1986
Comment options

Answer selected by Sreenath1986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #15 on September 02, 2022 14:19.