0

I'd like a caption on the figure, the short caption to appear in the list of figures, and to refer to the figure in the text. This seemed to work for me very recently and from my reading of the documentation here it ought to work still. To my dismay, I get an empty list of figures, a figure with no caption, and a ?? in the text. I'm compiling in RStudio by just hitting the "Compile PDF" button.

Am I missing something obvious?

\documentclass{article}
\usepackage{graphics}

\begin{document}
\SweaveOpts{concordance=TRUE}

\listoffigures

I'm referring to Figure~\ref{fig:wtf}.

<<wtf,echo=FALSE,fig=TRUE,fig.cap='test caption',fig.scap='tstcptn'>>=
plot(rnorm(1000))
@

<<si>>=
sessionInfo()
@

\end{document}

I recently updated to the latest version of R and RStudio. Below are the results of the sessionInfo() inside of the document.

R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.9.5 (Mavericks)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
loaded via a namespace (and not attached):
[1] tools_3.2.2

The result of cat(system('pandoc --version', intern=TRUE), sep = '\n') is

pandoc 1.15.0.6
Compiled with texmath 0.8.2.2, highlighting-kate 0.6.
...

I can't think of any additional information to provide ...

Zoë Clark
  • 1,334
  • 2
  • 13
  • 25
  • After updating R, did you run `update.packages(checkBuilt = TRUE)`? –  Oct 09 '15 at 23:48
  • I ran `update.packages()` several times and for good measure I just ran `update.packages(checkBuilt = TRUE)` too. No change. – Zoë Clark Oct 09 '15 at 23:53
  • `knitr` calls `tools::texi2pdf` which is supposed to "run latex and bibtex until all cross-references are resolved", but I've had problems with internal references not getting resolved completely. Usually calling `texi2pdf` an additional time on the `.tex` file produced by `knitr` does the trick. – Gregor Thomas Oct 09 '15 at 23:59
  • Running `tools::texi2pdf()` once again on the `.tex` file didn't work. – Zoë Clark Oct 10 '15 at 13:41
  • 1
    Is there also a fig.label = argument, so fig.label = "wtf"? I can't recall clearly. If that is correct, perhaps you also drop "fig:" when you create the reference in the text. – lawyeR Oct 10 '15 at 14:38
  • It's a common convention to including `fig:` as a prefix for any figure labels, but it's not automatic. If you're going to reference `\ref{fig:wtf}` then you need a figure labeled `\label{fig:wtf}`, and lawyeR is right, `fig.label = "fig:wtf"` is the way to use `knitr` to create that label. – Gregor Thomas Oct 10 '15 at 17:26
  • I really appreciate all the comments but we're not getting any closer to a solution. The default figure prefix is indeed `fig:` which is attached automatically to the chunk's name for use by `\label{}`. See the documentation for `fig.lp` [here](http://yihui.name/knitr/options/#chunk_options) – Zoë Clark Oct 10 '15 at 17:47
  • 1
    I'm pretty sure this is the same problem as http://stackoverflow.com/q/27592837/559676 Please let me know if I'm wrong. – Yihui Xie Oct 10 '15 at 18:06
  • Thanks @Yihui, that was it. I had checked the global "Weave Rnw" option (it was set to knitr) but didn't realize that there was also a project-specific "Weave Rnw" option. How could you tell that was the problem? Was it the presence of `\SweaveOpts{concordance=TRUE}`? – Zoë Clark Oct 11 '15 at 20:19
  • @ZoëClark Yes. `\SweaveOpts{}` is an Sweave specific command. – Yihui Xie Oct 12 '15 at 02:27

0 Answers0