* Some * RMarkdown drawing captions not showing

Essentially, I have an Rmd document configured as follows:

--- title: "Example" author: "me" date: "December 2014" output: pdf_document: fig_caption: yes keep_tex: yes -- 

Then in the document, I use ggplot2 to display some diagrams, for example:

 ```{r myLabel, fig.cap='My Caption'} qplot(1:10, 10:1) ``` 

Now, for some reason, I can’t explain or investigate deeper than this, the produced TeX does not contain a fig.env='figure' environment, even if I force it with fig.env='figure' . Instead, TeX has an includegraphics command:

 \includegraphics{journal_files/figure-latex/myLabel-1.pdf} 

Other figures in the same document have a digital environment with an inscription. Ie, TeX's "Knit PDF" output should produce:

 \begin{figure}[htbp] \centering \includegraphics{journal_files/figure-latex/myLabel-1.pdf} \caption{My Citation} \end{figure} 

The R Markdown log window displays only irrelevant things:

 label: myLabel (with options) List of 2 $ fig.cap: chr "My Caption" $ fig.env: chr "figure" cropping journal_files/figure-latex/myLabel-1.pdf PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek. 

Like me /

  • find out what exactly is happening (debug log?), as soon as I click "Knit PDF" and get to TeX (the "R Markdown" output window does not show errors and even echo files [missing] captions!),
  • or, better yet, did anyone have this problem and know what is wrong with RStudio, knitr and pandoc?
+7
rstudio knitr r-markdown pandoc
source share
1 answer

It turns out that the solution is quite simple: the RMarkdown compiler does not display captions for two consecutive digits, for example:

 ```{r myLabel1, fig.cap='My Caption 1'} qplot(1:10, 10:1) ``` ```{r myLabel2, fig.cap='My Caption 2'} qplot(1:10, 10:1) ``` 

or for a figure that is not separated from the text in a new paragraph, like this:

 ```{r myLabel1, fig.cap='My Caption 1'} qplot(1:10, 10:1) ``` As shown in Fig. 2, the inter-galactic distances are strongly correlated with the observed redshift ... 

There are no captions in this parameter, and the shape environment is not created in the TeX file.

Instead, there must be at least two characters in the interval (new line) between the two charts. Ie, this works beautifully, and both signatures show:

 ```{r myLabel1, fig.cap='My Caption 1'} qplot(1:10, 10:1) ``` ```{r myLabel2, fig.cap='My Caption 2'} qplot(1:10, 10:1) ``` 

Although this is a feature that allows you to enable embedded graphics, it would be nice if a warning message appears for the numbers with the argument fig.cap, which is not displayed.

+11
source share

All Articles