tests/testthat/examples/knitr-examples/035-optipng.md

This demos shows you how to optimize PNG images with optipng.

library(knitr)
opts_chunk$set(cache = TRUE)
knit_hooks$set(optipng = hook_optipng)

Now we set the chunk option optipng to a non-NULL value, e.g. '', to activate the hook.

library(methods)
library(ggplot2)
set.seed(123)
qplot(rnorm(1000), rnorm(1000))

plot of chunk use-optipng

Same plot, not optimized:

library(methods)
library(ggplot2)
set.seed(123)
qplot(rnorm(1000), rnorm(1000))

plot of chunk no-optipng

Same plot, most heavily optimized (pass -o7 to optipng):

library(methods)
library(ggplot2)
set.seed(123)
qplot(rnorm(1000), rnorm(1000))

plot of chunk optipng-o7



Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on Aug. 21, 2025, 5:27 p.m.