r bookdown pdf格式不起作用

时间:2017-05-06 05:12:51

标签: r pdf r-markdown bookdown

我在尝试使用bookdown编译pdf时遇到了很多问题。 Html和word格式工作得非常好。我正在运行Windows 10 64位。

我安装了最新的MiKTeX完整版。我也试过Basic,它没有解决问题。

这是我的会话信息:

    Session info --------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, mingw32             
 ui       RStudio (1.0.143)           
 language (EN)                        
 collate  Spanish_Spain.1252          
 tz       Europe/Paris                
 date     2017-05-06                  

Packages ------------------------------------------------------------------------------------------------
 package   * version date       source                           
 backports   1.0.5   2017-01-18 CRAN (R 3.3.2)                   
 base64enc   0.1-3   2015-07-28 CRAN (R 3.3.2)                   
 bitops      1.0-6   2013-08-17 CRAN (R 3.3.2)                   
 bookdown    0.3.14  2017-03-19 Github (rstudio/bookdown@3025188)
 caTools     1.17.1  2014-09-10 CRAN (R 3.3.2)                   
 digest      0.6.12  2017-01-27 CRAN (R 3.3.2)                   
 evaluate    0.10    2016-10-11 CRAN (R 3.3.2)                   
 highr       0.6     2016-05-09 CRAN (R 3.3.2)                   
 htmltools   0.3.6   2017-04-28 CRAN (R 3.3.3)                   
 jsonlite    1.4     2017-04-08 CRAN (R 3.3.3)                   
 knitr       1.15.1  2016-11-22 CRAN (R 3.3.2)                   
 magrittr    1.5     2014-11-22 CRAN (R 3.3.2)                   
 markdown    0.8     2017-04-20 CRAN (R 3.3.3)                   
 mime        0.5     2016-07-07 CRAN (R 3.3.2)                   
 Rcpp        0.12.10 2017-03-19 CRAN (R 3.3.2)                   
 rmarkdown   1.5     2017-04-26 CRAN (R 3.3.3)                   
 rprojroot   1.2     2017-01-16 CRAN (R 3.3.2)                   
 stringi     1.1.5   2017-04-07 CRAN (R 3.3.3)                   
 stringr     1.2.0   2017-02-18 CRAN (R 3.3.3)                   
 yaml        2.1.14  2016-11-12 CRAN (R 3.3.2)

这是错误:

> bookdown::render_book("index.Rmd", "bookdown::pdf_document2")


processing file: index.rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: index.knit.md



processing file: confidential-statement.Rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: confidential-statement.knit.md



processing file: signature-page.Rmd
  |................                                                 |  25%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |................................                                 |  50%
  ordinary text without R code

  |.................................................                |  75%
label: unnamed-chunk-2 (with options) 
List of 2
 $ echo     : logi FALSE
 $ out.width: chr "100%"

  |.................................................................| 100%
  ordinary text without R code


output file: signature-page.knit.md



processing file: abbreviations.Rmd
  |................                                                 |  25%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |................................                                 |  50%
  ordinary text without R code

  |.................................................                |  75%
label: tab1 (with options) 
List of 3
 $ echo   : logi FALSE
 $ message: symbol F
 $ warning: symbol F

  |.................................................................| 100%
  ordinary text without R code


output file: abbreviations.knit.md



processing file: background.Rmd
  |................                                                 |  25%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |................................                                 |  50%
  ordinary text without R code

  |.................................................                |  75%
label: unnamed-chunk-2 (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
   inline R code fragments


output file: background.knit.md



processing file: objectives.Rmd
  |......................                                           |  33%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |...........................................                      |  67%
label: unnamed-chunk-2 (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
   inline R code fragments


output file: objectives.knit.md



processing file: data.Rmd
  |...........                                                      |  17%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |......................                                           |  33%
  ordinary text without R code

  |................................                                 |  50%
label: unnamed-chunk-2 (with options) 
List of 1
 $ echo: logi FALSE

  |...........................................                      |  67%
   inline R code fragments

  |......................................................           |  83%
label: tab2 (with options) 
List of 3
 $ echo   : logi FALSE
 $ message: symbol F
 $ warning: symbol F

  |.................................................................| 100%
  ordinary text without R code


output file: data.knit.md



processing file: overview.Rmd
  |................                                                 |  25%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |................................                                 |  50%
  ordinary text without R code

  |.................................................                |  75%
label: unnamed-chunk-2 (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: overview.knit.md



processing file: reporting.Rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: reporting.knit.md



processing file: quality.Rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: quality.knit.md



processing file: references.Rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: references.knit.md



processing file: appendix1.Rmd
  |................                                                 |  25%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |................................                                 |  50%
  ordinary text without R code

  |.................................................                |  75%
label: tab3 (with options) 
List of 3
 $ echo   : logi FALSE
 $ message: symbol F
 $ warning: symbol F

  |.................................................................| 100%
  ordinary text without R code


output file: appendix1.knit.md



processing file: appendix2.Rmd
  |................................                                 |  50%
label: unnamed-chunk-1 (with options) 
List of 2
 $ include: logi FALSE
 $ cache  : logi FALSE

  |.................................................................| 100%
  ordinary text without R code


output file: appendix2.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output _main.tex --table-of-contents --toc-depth 2 --template "C:\Users\Mario\Documents\R\win-library\3.3\rmarkdown\rmd\latex\default-1.17.0.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable tables=yes --standalone 

======================================================================
starting package maintenance...
installation directory: C:\Users\Mario\AppData\Roaming\MiKTeX\2.9
package repository: ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/
visiting repository ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/...
repository type: remote package repository
loading lightweight database...
downloading ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/miktex-zzdb1-2.9.tar.lzma...
166037 bytes, 188.54 KB/Sec
lightweight database digest: caad893b956d1cfa62503ece5da1dbab
going to download 324623 bytes
going to install 24 file(s) (1 package(s))
downloading ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/latexmk.tar.lzma...
324623 bytes, 780.82 KB/Sec
extracting files from latexmk.tar.lzma...
======================================================================

Latexmk, John Collins, 19 Jan. 2017. Version 4.52c

Output created: _book/_main.pdf
Error in tools::file_path_as_absolute(output_file) : 
  file '_book/_main.pdf' does not exist
In addition: Warning messages:
1: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -v' had status 1 
2: The LaTeX package latexmk was not correctly installed. 
3: running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe" -v' had status 1 
4: running command '"pdflatex" -halt-on-error -interaction=batchmode "_main.tex"' had status 1 
5: running command '"bibtex" "_main.aux"' had status 1 
6: running command '"pdflatex" -halt-on-error -interaction=batchmode "_main.tex"' had status 1 
7: running command '"pdflatex" -halt-on-error -interaction=batchmode "_main.tex"' had status 1 

我真的不明白为什么说latexmk.exe没有正确安装。

它位于以下目录中:C:\ Program Files \ MiKTeX 2.9 \ miktex \ bin \ x64 \ latexmk.exe

另外,当我跑:

bookdown::render_book("index.Rmd", "bookdown::pdf_document2")
在R中,latexmk似乎有效。这是latexmk.log文件的输出,位于:C:\ Users \ Mario \ AppData \ Local \ MiKTeX \ 2.9 \ miktex \ log

2017-05-06 06:41:14,090+0200 INFO  latexmk - starting with command line: C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe -v
2017-05-06 06:41:14,092+0200 INFO  latexmk - running 'initexmf --enable-installer --quiet --update-fndb' to refresh the file name database
2017-05-06 06:41:21,041+0200 INFO  latexmk - running 'initexmf --enable-installer --quiet --mklangs' to refresh language.dat
2017-05-06 06:41:21,413+0200 INFO  latexmk - starting with command line: latexmk -v
2017-05-06 06:41:21,428+0200 INFO  latexmk - installing package latexmk triggered by scripts\latexmk\latexmk.pl
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: starting package maintenance...
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: installation directory: C:\Users\Mario\AppData\Roaming\MiKTeX\2.9
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: package repository: ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: visiting repository ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/...
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: repository type: remote package repository
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: loading lightweight database...
2017-05-06 06:41:22,651+0200 INFO  latexmk - mpm: downloading ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/miktex-zzdb1-2.9.tar.lzma...
2017-05-06 06:41:23,513+0200 INFO  latexmk - mpm: 166037 bytes, 188.54 KB/Sec
2017-05-06 06:41:23,667+0200 INFO  latexmk - mpm: lightweight database digest: caad893b956d1cfa62503ece5da1dbab
2017-05-06 06:41:23,667+0200 INFO  latexmk - mpm: going to download 324623 bytes
2017-05-06 06:41:23,667+0200 INFO  latexmk - mpm: going to install 24 file(s) (1 package(s))
2017-05-06 06:41:23,667+0200 INFO  latexmk - mpm: downloading ftp://mirrors.rit.edu/CTAN/systems/win32/miktex/tm/packages/latexmk.tar.lzma...
2017-05-06 06:41:24,082+0200 INFO  latexmk - mpm: 324623 bytes, 780.82 KB/Sec
2017-05-06 06:41:24,082+0200 INFO  latexmk - mpm: extracting files from latexmk.tar.lzma...
2017-05-06 06:41:31,696+0200 INFO  latexmk - starting with command line: C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\latexmk.exe -v
2017-05-06 06:44:20,358+0200 INFO  latexmk - starting with command line: latexmk.exe
2017-05-06 06:45:03,011+0200 INFO  latexmk - starting with command line: "C:\Program Files\MiKTeX 2.9\miktex\bin\x64\latexmk.exe"

有任何建议或想法吗?

提前致谢,

马里奥

1 个答案:

答案 0 :(得分:2)

虽然我仍然不确定根本原因,但我发现system2('pdflatex', 'foo.tex', stdout = FALSE)在使用OP进行调试时无法正常工作。我在 rmarkdown 程序包on Github中提供了一个修复程序,当system2('pdflatex', 'foo.tex')不起作用时,它基本上会回退到stdout = FALSE。似乎重定向到/dev/null在某些Windows平台上不起作用。