Skip to contents

A target for exporting a plot target as a png.

Usage

tar_png(
  plot_target,
  width = 9,
  height = 5,
  dpi = 300,
  units = c("in", "cm", "mm", "px"),
  export_path = "exports/figures"
)

Arguments

plot_target

the name of the target that will generate the plot to export

width, height, units

Plot size in units ("in", "cm", "mm", or "px"). If not supplied, uses the size of current graphics device.

dpi

Plot resolution. Also accepts a string input: "retina" (320), "print" (300), or "screen" (72). Applies only to raster output types.

export_path

the destination path of the exported plot file

Value

A target object for exporting a plot as a png.

Details

The name of the returned target will be the name of the plot target with the prefix export_. The file name of the exported plot will be that of the argument provided to plot_target.

Examples

if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
  targets::tar_dir({
    targets::tar_script({
      list(
        targets::tar_target(
          iris_plot,
          ggplot2::ggplot(
            iris,
            ggplot2::aes(
              x = Sepal.Length,
              y = Sepal.Width
            ) 
          ) +
            ggplot2::geom_point()
        ),
        jftargets::tar_png(iris_plot)
      )
    })
    
    targets::tar_make()
    tar_read(export_iris_plot)
  })
}