Saving R Baseplots As Objects & Plotting Those Objects
Sreenath1986 opened this issue · comments
Description
I 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 example
Below code goes in functions.R file
Define a function to create & return a R baseplot (boxplot in this case)
fn_baseplot <- function(dataset){ t <- boxplot(mpg~cyl, data=mtcars) return(t) }
Define a function to create & return a R ggplot (again boxplot)
fn_ggplot <- function(dataset){ t <- boxplot(mpg~cyl, data=mtcars) return(t) }
Below code goes in _targets.R file
Create targets objects based on the above two functions
library(targets) data(mtcars) source("functions.R") list( tar_target(tar_baseplot, fn_baseplot(mtcars)), tar_target(tar_ggplot, fn_ggplot(mtcars)) )
Verifying the targets objects
tar_load(tar_ggplot) plot(tar_ggplot)
Prints the box plot
tar_load(tar_baseplot) plot(tar_baseplot)
Below error message
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
`