Skip to content

Saving R Baseplots As Objects & Plotting Those Objects #15

@Sreenath1986

Description

@Sreenath1986

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'

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions