Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No figures generated when outputting to .tex #582

Closed
emiltb opened this issue May 24, 2018 · 4 comments
Closed

No figures generated when outputting to .tex #582

emiltb opened this issue May 24, 2018 · 4 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@emiltb
Copy link

emiltb commented May 24, 2018

I would like to use rmarkdown::latex_document() to generate a .tex-file and figures, that can then be converted to PDF using latexmk. I have a rather long table, which only renders correctly if I create my PDF using latexmk, since tinytex::latexmk()'s emulated version seems to run xelatex too few times. I found, the global option to make that possible, options(tinytex.latexmk.emulation = FALSE), and that correctly renders the PDF. However, since bookdown deletes all of the intermediate files generated by latexmk, the PDF often takes unnecessarily long to build. For this reason, I would like to just get the .tex-file and figures, and then automate PDF-generation via a Makefile. This is, however, not possible since the figures are not generated when using rmarkdown::latex_document(), even though it is a documented possibility.

This small example illustrates the issue. When I use the Build command in RStudio, this runs rmarkdown::render_site(encoding = 'UTF-8') and produces the .tex-file, but the corresponding figure is not created.

---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: memoir
output:
  rmarkdown::latex_document: default
---
  
  # Hello World
  
  Hi. Bye.

```{r message=FALSE, warning=FALSE}
library(tidyverse)

tibble(a = runif(n = 10), b = runif(10)) %>% 
  ggplot(aes(a, b)) +
  geom_point()
```

Info about my system:

> devtools::session_info('bookdown')
  Session info ---------------------------------------------------------------------------------------------------------------
    setting  value                       
  version  R version 3.4.4 (2018-03-15)
  system   x86_64, linux-gnu           
  ui       RStudio (1.1.453)           
  language en_US:en                    
  collate  en_US.UTF-8                 
  tz       Europe/Copenhagen           
  date     2018-05-24                  
  
  Packages -------------------------------------------------------------------------------------------------------------------
    package   * version date       source                        
  backports   1.1.2   2017-12-13 CRAN (R 3.4.4)                
  base64enc   0.1-3   2015-07-28 CRAN (R 3.4.4)                
  bookdown    0.7.10  2018-05-18 local                         
  digest      0.6.15  2018-01-28 CRAN (R 3.4.4)                
  evaluate    0.10.1  2017-06-24 CRAN (R 3.4.4)                
  glue        1.2.0   2017-10-29 CRAN (R 3.4.4)                
  graphics  * 3.4.4   2018-03-16 local                         
  grDevices * 3.4.4   2018-03-16 local                         
  highr       0.6     2016-05-09 CRAN (R 3.4.4)                
  htmltools   0.3.6   2017-04-28 CRAN (R 3.4.4)                
  jsonlite    1.5     2017-06-01 CRAN (R 3.4.4)                
  knitr       1.20    2018-02-20 CRAN (R 3.4.4)                
  magrittr    1.5     2014-11-22 CRAN (R 3.4.4)                
  markdown    0.8     2017-04-20 CRAN (R 3.4.4)                
  methods   * 3.4.4   2018-03-16 local                         
  mime        0.5     2016-07-07 CRAN (R 3.4.4)                
  Rcpp        0.12.17 2018-05-18 CRAN (R 3.4.4)                
  rmarkdown   1.9     2018-03-01 CRAN (R 3.4.4)                
  rprojroot   1.3-2   2018-01-03 CRAN (R 3.4.4)                
  stats     * 3.4.4   2018-03-16 local                         
  stringi     1.2.2   2018-05-02 CRAN (R 3.4.4)                
  stringr     1.3.1   2018-05-10 CRAN (R 3.4.4)                
  tinytex     0.5.4   2018-05-17 Github (yihui/tinytex@f9aba40)
  tools       3.4.4   2018-03-16 local                         
  utils     * 3.4.4   2018-03-16 local                         
  xfun        0.1     2018-01-22 CRAN (R 3.4.4)                
  yaml        2.1.19  2018-05-01 CRAN (R 3.4.4)                
> rmarkdown::pandoc_version()
  [1] ‘1.19.2.1’
> system('pdflatex --version')
  pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018)
  kpathsea version 6.3.0
  Copyright 2018 Han The Thanh (pdfTeX) et al.
  There is NO warranty.  Redistribution of this software is
  covered by the terms of both the pdfTeX copyright and
  the Lesser GNU General Public License.
  For more information about these matters, see the file
  named COPYING and the pdfTeX source.
  Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
  Compiled with libpng 1.6.34; using libpng 1.6.34
  Compiled with zlib 1.2.11; using zlib 1.2.11
  Compiled with xpdf version 4.00  
@yihui
Copy link
Member

yihui commented May 24, 2018

You can set options(tinytex.clean = FALSE) to avoid cleaning up the auxiliary files generated by latexmk.

That said, this sounds like a bug of rmarkdown::latex_document. I'll investigate it.

@yihui yihui added this to the v0.8 milestone May 24, 2018
@yihui yihui added the bug an unexpected problem or unintended behavior label May 24, 2018
@yihui
Copy link
Member

yihui commented May 24, 2018

Fixed in the development version of rmarkdown:

devtools::install_github('rstudio/rmarkdown')

Thanks for the report!

@emiltb
Copy link
Author

emiltb commented May 25, 2018

options(tinytex.clean = FALSE) effectively solved my problem, so thank you for that solution.

I tested the updated version of rmarkdown, and the figure is saved now, but it seems that the pdf device for some reason doesn't capture all elements of the plot. I have attached the PDF-output I get here.
unnamed-chunk-1-1.pdf

yihui added a commit to RLesur/rmarkdown that referenced this issue Apr 1, 2019
… the latex_document() format, so that clean_supporting = FALSE
@github-actions
Copy link

github-actions bot commented Nov 6, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants