---
title: "Save plots using recordr and knitr"
author: "Sara Moore"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Using recordr with knitr}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

This is an attempt to set up a chunk hook for adding plots to the
recordr data store "invisibly."

Currently, this hook function works for the last ggplot object plotted.


```{r createsolrconn}
library(recordr)
library(histry)
kt = knitr_tracker()
vtdb = jsonVTDB(tempfile(), img_dir = tempdir())
defaultVTDB(vtdb)
```

```{r setopts, echo=FALSE, cache=FALSE}
library(knitr)
knit_hooks$set(plot = recordr:::recplothook)
opts_chunk$set(
    out.width='\\textwidth',
    fig.height=8, fig.width=12.8, dpi=300,
    # tidy.opts=list(width.cutoff=200),
    # global.device = TRUE,
    fig.align='center', message=FALSE, cache=2
    )
```

```{r testrecordr1}
library(ggplot2)
qplot(speed, dist, data = cars)
```

```{r testrecordr2}
p = qplot(speed, dist, data = cars)
p = p + geom_smooth()
p + geom_jitter()
```

```{r}
vtdb
```