rstudio / rmarkdown-book

R Markdown: The Definitive Guide (published by Chapman & Hall/CRC in July 2018)
https://bookdown.org/yihui/rmarkdown
Other
781 stars 518 forks source link

Compilation failure building pdf #39

Closed gvwilson closed 5 years ago

gvwilson commented 6 years ago
  1. Clone repo.
  2. make pdf.
  3. Install a bunch of packages (list below).
  4. Finally get this far with make pdf on the command line, but still no PDF.

    
    ~/rmarkdown-book + master$ make pdf
    Rscript --quiet _render.R "bookdown::pdf_book" &&\
    mv _book/rmarkdown.pdf _book/rmarkdown-full.pdf
    Error: Functions that produce HTML output found in document targeting latex output.
    Please change the output type of this document to HTML. Alternatively, you can allow
    HTML output in non-HTML formats by adding this option to the YAML front-matter of
    your rmarkdown file:
    
    always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

Execution halted Error: Failed to compile the book to bookdown::pdf_book Execution halted make: *** [pdf] Error 1


Packages installed (in order, as error messages come up):
- revealjs
- bookdown
- blogdown
- rticles
 - flexdashboard
- learnr
- pkgdown
- xaringan
- tufte
yihui commented 6 years ago

You need the R package webshot and PhantomJS because this book contains HTML widgets: https://bookdown.org/yihui/rmarkdown/interactive-documents.html

gvwilson commented 6 years ago

Thanks - is there something like Python's requirements.txt for R that lists all requirements in a runnable way? I know about DESCRIPTION for packages, but according to https://stackoverflow.com/questions/38928326/is-there-something-like-requirements-txt-for-r, the only answer for applications is to put package installation commands in a script.

gvwilson commented 6 years ago

Compilation to PDF still isn't working for me:

In RStudio:

> install.packages("webshot")
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.5/webshot_0.5.1.tgz'
Content type 'application/x-gzip' length 128111 bytes (125 KB)
==================================================
downloaded 125 KB

The downloaded binary packages are in
    /var/folders/cg/b541v521215207m3fnkzd77w0000gn/T//RtmpMFHd7C/downloaded_packages
> library(webshot)
> webshot::install_phantomjs()
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   616    0   616    0     0   2  0  273      0 --:--:-- --:--:-- --:--:--  2273
 22 16.3M   22  989k    0     0    99k 100 16.3M  100 16.3M    0     0  2870k      0  0:
phantomjs has been installed to /Users/gvwilson/Library/Application Support/PhantomJS

and then on the command line:

$ make pdf
Rscript --quiet _render.R "bookdown::pdf_book" &&\
    mv _book/rmarkdown.pdf _book/rmarkdown-full.pdf
Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

Execution halted
Error: Failed to compile the book to bookdown::pdf_book
Execution halted
make: *** [pdf] Error 1

make pdf2 produces a similar report.

yihui commented 6 years ago

How about bookdown::clean_book() in R and rerun?

Creating PDF is the most complicated task because the toolchain is much longer than other formats such as HTML. It was intentional that I didn't make this task easier. If I want, I can certainly automate it to an extent that you can simply run make pdf to generate a PDF. I don't want to spend time on this because (1) I don't encourage average users to create PDF but try HTML first; (2) Our publisher has been generous enough to allow a free web version of this book, and I think it is fair for me to leave the final exercise to those who really really want to build a PDF version of this book.

pcarbo commented 6 years ago

@yihui I was able to successfully build the HTML (make gitbook) but, like @gvwilson, I also got the same error, even after following your instructions in this Issue above. Here is the error I get, as well as my sessionInfo, from running make pdf:

$ make pdf
Rscript  _render.R "bookdown::pdf_book" &&\
    mv _book/rmarkdown.pdf _book/rmarkdown-full.pdf

R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

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  base

loaded via a namespace (and not attached):
[1] compiler_3.4.3

output file: rmarkdown.knit.md

Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

Thanks!

yihui commented 6 years ago

@pcarbo All R packages up-to-date? (Your R version is old but 3.4.3 should be fine)

yihui commented 6 years ago

I forgot to mention that you also need to delete the _bookdown_files directory.

pcarbo commented 6 years ago

Thanks @yihui for the quick response! It seems that I am almost there. I re-installed the packages as you recommended, and deleted _bookdown_files. After the pandoc command, I get this error:

/Users/pcarbo/anaconda3/bin/pandoc +RTS -K512m -RTS rmarkdown.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output rmarkdown.tex --table-of-contents --toc-depth 3 --self-contained --number-sections --highlight-style tango --latex-engine xelatex --natbib --include-in-header latex/preamble.tex --include-before-body latex/before_body.tex --include-after-body latex/after_body.tex --top-level-division=chapter --wrap=none --variable tables=yes --standalone
Error in post(x) : Table 16.1 not found
Calls: <Anonymous> ... render_cur_session -> <Anonymous> -> <Anonymous> -> post
Execution halted
yihui commented 6 years ago

From /Users/pcarbo/anaconda3/bin/pandoc, you seem to be using a custom version of Pandoc, and I don't know which version it is. RStudio Preview has included Pandoc 2.2.1, which is what I use to build the book to PDF: https://bookdown.org/yihui/rmarkdown/software-info.html

pcarbo commented 6 years ago

@yihui Indeed, that is the key---it worked when I installed RStudio v1.2.1013-1 Preview from here, then running bookdown::render_book("index.Rmd",output_format="bookdown::pdf_book"), but only after removing this line,

monofont: "Source Code Pro"

from index.Rmd because it said that this font could not be found.

Thanks!

yihui commented 6 years ago

No problem. "Source Code Pro" was one element of the "long toolchain" I mentioned above. I think you can download the font from Google Fonts, or https://google-webfonts-helper.herokuapp.com/fonts.