Hi!

I am preparing a PDF, which has lots of figures and tables. I wanted to add captions to all of them automatically, but was not successful, as you can see here.

As an workaround, I am using the `caption`

package to add caption to each one of them separately, like the following.

```
---
title: "Example"
date: "28 April 2018"
output: pdf_document
header-includes:
- \usepackage{caption}
---
```{r include = FALSE}
x <- rnorm(10)
pdf("first.pdf")
plot(x)
dev.off()
y <- rcauchy(10)
pdf("second.pdf")
plot(y)
dev.off()
z <- runif(10)
pdf("third.pdf")
plot(z)
dev.off()
```
Bla...Bla...Bla
\includegraphics{first.pdf}
\captionof{figure}{normal}
Bla...Bla...Bla
\begin{center}
\begin{tabular}{r}
\hline
x\\
\hline
0.0017384\\
\hline
0.0191490\\
\hline
0.0661849\\
\hline
0.0341861\\
\hline
0.0044048\\
\hline
0.0285763\\
\hline
0.0118869\\
\hline
0.0358421\\
\hline
0.0262538\\
\hline
0.0065091\\
\hline
0.0185175\\
\hline
0.0126261\\
\hline
0.0022572\\
\hline
0.0094838\\
\hline
0.0734565\\
\hline
0.0248889\\
\hline
0.0122629\\
\hline
0.0047293\\
\hline
0.1004818\\
\hline
0.0067478\\
\hline
\end{tabular}
\captionof{table}{shapiro}
\end{center}
Bla...Bla...Bla
\includegraphics{second.pdf}
\captionof{figure}{}
Bla...Bla...Bla
\includegraphics{third.pdf}
\captionof{figure}{uniform}
Bla...Bla...Bla
\begin{center}
\begin{tabular}{r|r|r|r|r|r|r|r|r|r}
\hline
-1.5569048 & -1.2940827 & 1.7106294 & 0.1723490 & -2.1006933 & -0.8110029 & 1.3568960 & 0.3838090 & -0.0664289 & 1.0860245\\
\hline
-0.0006826 & 0.0738968 & 0.6309370 & 0.9382452 & -0.8759342 & 1.0677394 & -0.1363563 & 1.7599148 & -0.5858252 & 2.3932724\\
\hline
0.7751907 & 1.3758625 & -0.4498818 & -0.6188443 & 0.1046838 & 1.3741381 & -0.0546395 & 0.2451491 & -1.2914554 & 0.9379431\\
\hline
-0.1828093 & 0.4569917 & -0.4182240 & -0.3978720 & 0.6531548 & -1.2027918 & -0.6495577 & 0.4871754 & -0.9405698 & -1.6928845\\
\hline
1.1212768 & 1.7779455 & 0.9141339 & 1.5619030 & -0.1583376 & 0.8200586 & 1.2796174 & -0.4995602 & -1.5686963 & -0.2077684\\
\hline
\end{tabular}
\captionof{table}{}
\end{center}
Bla...Bla...Bla
\begin{center}
\begin{tabular}{r}
\hline
x\\
\hline
0.0023577\\
\hline
0.1127297\\
\hline
0.0023940\\
\hline
0.0053369\\
\hline
0.0279039\\
\hline
0.3645155\\
\hline
0.0052540\\
\hline
0.0408357\\
\hline
0.0220720\\
\hline
0.0026888\\
\hline
0.0036803\\
\hline
0.0033165\\
\hline
0.0931782\\
\hline
0.3248195\\
\hline
0.0003181\\
\hline
0.1183903\\
\hline
0.4139152\\
\hline
0.0010397\\
\hline
0.0028948\\
\hline
0.3686759\\
\hline
\end{tabular}
\captionof{table}{kolmogorov}
\end{center}
```

The above yields Example.pdf (80.8 KB).

But in this way, for every figure, first I need to save the graph separately and then use

```
\begin{center}
\includegraphics{some_filename.pdf}
\captionof{figure}{some_text}
\end{center}
```

Obviously, the best solution would be to automate captions as the R codes generate graphs, but as that failed, I would like to call something of the sort `caption(type, text)`

within the code chunk and it will create a caption named text (possibly blank) starting with "Figure k" or "Table l" etc.

Is it possible to achieve this?

Thanks.