76

When building a package, I received the following warning:

* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.

I have no idea how to even begin diagnosing this. Is there a tool that tells me what .Rd file the problem is in?

I get no warnings about any of my Rd files in the checking documentation step....

Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
  • 4
    I use the `devtools` packages for this. I can't even imagine how hard package building will be without it. – Andrie May 30 '12 at 16:08
  • @Andrie Now that I'm transitioning to dissertating full-time, one of my goals for the next few months is to invest in an optimal workflow. So I'm switching over to devtools soon, but haven't learnt it yet. :-( – Ari B. Friedman May 30 '12 at 19:17
  • 1
    FWIW, I randomly started getting these errors, and after a couple days of trying to debug latex code and trying all sorts of fixes on the internet, I did a clean install of mactex and all the errors disappeared. – rawr Dec 18 '14 at 15:23
  • 1
    actually I take that back. It has broken again and getting the same errors. Seems to be a [known issue](https://github.com/hadley/devtools/issues/63), but hadley's solution here works, ie, `R CMD build ./package` `R CMD check ./....tar.gz` from the command line – rawr Dec 19 '14 at 05:22

8 Answers8

74

Try R CMD Rd2pdf mypackage to create the manual, and possibly also set the --no-clean option to keep the temporary files. This should allow you to debug the LaTeX code triggering the error.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 3
    That did it. Thanks. Seems the error was due to a missing `inconsolata.sty` file, which I attribute to Ubuntu being horridly behind on its LaTeX updates. I'm installing TeX Live manually and that will hopefully help me stay up-to-date. – Ari B. Friedman May 30 '12 at 19:43
  • 19
    That is not quite the correct conclusion in my book. `inconsolata.sty` is simply in another texlive fonts package: texlive-fonts-extra. And I seem to have added it the Suggests of the `r-base-dev` package as well. – Dirk Eddelbuettel May 30 '12 at 20:44
  • 5
    Yes, that was not the most logical rant. When I looked for TexLive to install the package containing inconsolata, I found I didn't have texlive installed in Ubuntu. When I went to install it via the package repository, I realized it was 2+ years out-of-date. Then I turned into a giant ogre posting silly things across the internets. – Ari B. Friedman May 30 '12 at 20:56
  • 1
    This `R CMD Rd2pdf mypackage --no-clean` worked great for me, too. Also, my problem was solved by installing the recommended fonts for tex-live, a meta-package called `texlive-collection-fontsrecommended`... In case you don't want to play whack-a-mole with missing fonts – Paul 'Joey' McMurdie Feb 22 '14 at 21:19
  • 32
    In my case it was a missing `texi2dvi` required to build the document index; I corrected this with `sudo apt-get install texinfo` – dardisco Apr 02 '14 at 21:31
  • 2
    I took me a while to figure out that once you have run `R CMD Rd2pdf mypackage --no-clean`, you can inspect the Latex file in `mypackage.Rcheck/mypackage-manual.tex` for errors. – Paul Rougieux Feb 15 '16 at 14:12
  • Thank you @dardisco, that solved it for me too (Linux Mint) – Dominic Comtois Feb 15 '19 at 10:14
19

Though @Dirk's answer also helped me to fix the problem I would like to add a bit which might especially help recent updaters. That is, people who haven't encountered other LaTeX / R troubles after the update to 3.1.3 yet. The problem is little bit more general than just building. For me, on OS X the problem was that R CMD Rd2pdf as well as the R CMD CHECK expected texi2dvi to be in /usr/local/bin while it was in /usr/bin. A symlink helped to fix the problem. On terminal type:

# to check whether the same issue exists for you
which texi2dvi
# if so
cd /usr/local/bin
ln -s /usr/bin/texi2dvi

Of course if the first line returns something else, you need to adapt the symlink here.

Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
  • Thanks! symlink solved the issue for me on OS X with R 3.1.3. In my case it worked with paths in inverted: ln -s /usr/bin/texi2dvi /usr/local/bin/texi2dvi – jburkhardt Mar 26 '15 at 15:11
  • @Johannes yes you're right. It's `ln -s source_file target file`. If you `cd` to the target destination first you only need to pass the source. – Matt Bannert Mar 26 '15 at 15:34
  • 2
    For me on Linux Mint 17.1 (built on Ubuntu 14.04), I needed `texinfo`, not `texi2dvi`. Thanks for the tip and to [this](http://stackoverflow.com/questions/17652698/texi2dvi-command-not-found) question for teaching me the analog! – MichaelChirico Sep 24 '15 at 00:27
  • I have: `which texi2dvi` > `/usr/local/bin/texi2dvi`. But I don't know if it is the cause of `/usr/local/bin/texi2dvi: makeindex failed`, `Error in running tools::texi2pdf()`. Any ideas how can I track the error? – Pablo Casas Jun 15 '20 at 03:05
7

Concluding from the comments and from my own experience the problem often seems to be that some TeX fonts are missing, most often

  • inconsolata.sty and
  • upquote.sty

First you have to find the right directory where TeX fonts are stored - in my case this is:

C:\Program Files\R\R-3.3.0\share\texmf\tex\latex

Then you can download them here:

Just copy them to the respective folder and in many cases the problem will be solved (in my case too). This should work for all operating systems.

vonjd
  • 4,202
  • 3
  • 44
  • 68
5

...and another reason is that you haven't installed MikTex yet.

  1. Download MikTex from here and follow the dialog prompts to install. I found the defaults to be reasonable and worked well for me.

  2. Try to build your R package again. It should be OK now.

hackR
  • 1,459
  • 17
  • 26
2

In my case, I had no error when running devtools::check() nor devtools::document() but when running R CMD check mypackage_version.tar.gz I got an error:

* checking PDF version of manual ... WARNING
LaTeX errors when creating PDF version.
This typically indicates Rd problems.
LaTeX errors found:
* checking PDF version of manual without hyperrefs or index ... ERROR

In this question in RStudio Community they point to a problem with LATEX installation. I have the LATEX installation suggested in R markdown cookbook: TinyTex. I fixed the issue by running in the R console

tinytex::latexmk(file = "../mypackage.Rcheck/mypackage-manual.tex")

This command automatically updated my LATEX installation so the output file mypackage-manual.pdf was created. After this, I did not get any other error related to PDF when running R CMD check:

* checking PDF version of manual ... OK
* DONE
josep maria porrà
  • 1,198
  • 10
  • 18
1

If you are on Ubuntu just install Tex Live by this command: apt-get install texlive and restart Rstudo if you use it.

koralgooll
  • 392
  • 1
  • 3
  • 12
0

First, @dirk-eddelbuettel's approach in the current question identified the missing tex package (which was "makeindex" in my case).

system("R CMD Rd2pdf --no-preview --output=./documentation-peek.pdf ." )

# ... <omitted pages of output> ...
# Warning in sys2(makeindex, shQuote(idxfile)) : '"makeindex"' not found
# Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
#    unable to run 'makeindex' on 'Rd2.idx'
# Error in running tools::texi2pdf()

Then @pedro-lima's answer in https://stackoverflow.com/a/69968791/1082435 worked for my specific case.

tinytex::tlmgr_install("makeindex")
wibeasley
  • 5,000
  • 3
  • 34
  • 62
0

Oftentimes this error occur because of Unicode characters in the package. In this cases, the error message might look like this.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
! Package inputenc Error: Unicode character  (U+009D)
(inputenc)                not set up for use with LaTeX.

You can find any Unicode characters in your package using tools::showNonASCIIfile(). Here's a simple way to check for these characters in your functions and documentation:

# functions
functions <- list.files(path = './R', all.files = T, recursive = T, full.names = T)
lapply(X=functions, FUN = tools::showNonASCIIfile)

# documentation
docs <- list.files(path = './man', all.files = T, recursive = T, full.names = T)
lapply(X=docs, FUN = tools::showNonASCIIfile)
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109