As plots are generated in a knitr document, encode the code used to produce them into the resulting PNG files. This can be done by setting the chunk option: figasaur = TRUE after setting knit_hooks$set(figasaur = hook_figasaur) at the top of your knitr document. The knitr_example.Rmd file included in this package shows a simple example.

hook_figasaur(before, options, envir)

Arguments

before, options, envir

Arguments as required by knitr; please see references for details

Details

Note that this only works for PNG files generated for HTML documents, though it does work when the PNGs are embedded in the HTML file (e.g. using the self_contained option in rmarkdown::render. See knitr::opts_hooks for more information.

References

https://yihui.name/knitr/hooks#chunk_hooks

See also

encode

Author

David L Miller

Examples

writeLines(readLines( system.file("knitr_example.Rmd", package = "stegasaur")))
#> --- #> title: A simple example of `figasaur` hook in `knitr` #> author: David L Miller #> #> --- #> #> ```{r} #> library(knitr) #> knit_hooks$set(figasaur = stegasaur::hook_figasaur) #> ``` #> #> # A brief example #> #> Here we show that when we make the figure we can read it back in and get the code that generated it back. #> #> ```{r figasaur = TRUE} #> plot(sample(100)) #> ``` #> #> We could now use `stegasaur::decode` on the resulting file to find out how the figure was created (this should display `plot(sample(100))`).