knit2pdf failing to produce pdf in Shiny Apps - r

As the title states, I am attempting create a shiny application that can generate a pdf file that a user can then download. (Note that this is not a duplicate question because I have not found a question with a similar error)
In my search for a solution, I found this gist by the Knitr package author: https://gist.github.com/yihui/6091942, which I am attempting to recreate. There are also questions on S.O that use the same code, out = knit2pdf('input.Rnw', clean = TRUE) but all of them seem to date to before the 3.2.3 release of R.
The error I am given is:
output file: input.tex
Warning: running command '"pdflatex" -interaction=nonstopmode "input.tex"' had status 1
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
unable to run 'pdflatex' on 'input.tex'
Warning: Error in texi2dvi: unable to run 'pdflatex' on 'input.tex'
Stack trace (innermost first):
52: texi2dvi
51: tools::texi2pdf
50: knit2pdf
49: download$func [D:...\App-2/server.R#44]
1: shiny::runApp
What I have tried so far:
Updating R, RStudio, knitr package and my TeX distribution (TeXLive). I know that TeXLive is not the issue as I use it daily, and I can create a dummy .Rnw that will compile perfectly using the Compile PDF button in R Studio. I have also tried using knit() or render() and those will generate .tex files without giving an error. I have also changed my working directory to the app folder as suggested by another S.O. question, but that didn't solve my problem either.
Edit, Additional information: I am using Windows 10
Any suggestions welcome!

I don't think TeXLive is working completely. On Windows, RStudio recommends using MiKTeX, and so does Pandoc.

Related

R MarkDown Error: pandoc version 1.12.3 or higher is required and was not found

I'm using R Studios Cloud but I am suddenly experiencing difficulty knitting my markdown in any format (html, pdf & word).
This is the error I'm thrown when I press the knit button:
pandoc version 1.12.3 or higher is required and was not found (see the help page ?
rmarkdown::pandoc_available).
Execution halted
I then check if pandoc is installed via pandoc_available():
> pandoc_available()
[1] FALSE
False, so I try to install pandoc again? (I do not recall uninstalling it)
> installr::install.pandoc()
sh: 1: ifconfig: not found
Error in system("ifconfig", intern = TRUE) : error in running command
However, again I get another error for ifconfig: not found.
I am new to learning R and programming as a whole. I'm quite stumped. I have checked recent threads including popular solutions (linked below) to no avail.
I have also tried opening a new markdown file but still could not get knit to work.
I'd appreciate any help on this one.
popular solution to resolve pandoc version 1.12.3 error
Found the solution.
Relaunch your project by clicking on the 3 dots in the upper right corner.
See thread here.
Seems to be a common error happening to a lot of r studio cloud users in the past 24 hours.

Rmarkdown tabu.sty error in PDF output with libraries

Hello R community i'm trying to knit a pdf document, but get an error and cannot find the right answer in any forum. I'm using the latest R(4.1) and Rstudio(1.4). I have MiKTeX installed but I can not get a pdf to write unless I changed the global setting in R to write from tiny tex.
I have isolated the problem in the script. If I try to knit the document without loading any libraries, the document WILL knit. If I try to knit with libraries, then I throw a tabu.sty error. The problem here is I need the libraries for tables, graphs, etc.
! LaTeX Error: File `tabu.sty' not found.
! Emergency stop.
<read *>
Error: LaTeX failed to compile Chapter0.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Chapter0.log for more info.
Execution halted```

RMarkdown not compiling into PDF

I need to use RMarkdown to compile into one pdf but its not working. All my scripts work perfectly on their own but dont want to create the pdf in RMarkdown. What do I need to do, I don't use RMarkdown enough to know what to do.
Here is my error output:
output file: R-Markdown-Midterm.knit.md
A new version of TeX Live has been released. If you need to install or update any LaTeX packages, you have to upgrade TinyTeX with tinytex::reinstall_tinytex(). If it fails to upgrade, you might be using a default random CTAN mirror that has not been fully synced to the main CTAN repository, and you need to wait for a few more days or use a CTAN mirror that is known to be up-to-date (see the "repository" argument on the help page ?tinytex::install_tinytex()).
tlmgr: Local TeX Live (2019) is older than remote repository (2020).
Cross release updates are only supported with
update-tlmgr-latest(.sh/.exe) --update
See https://tug.org/texlive/upgrade.html for details.
! LaTeX Error: File `xcolor.sty' not found.
! Emergency stop.
<read *>
Error: LaTeX failed to compile R-Markdown-Midterm.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See R-Markdown-Midterm.log for more info.
In addition: Warning messages:
1: In in_dir(input_dir(), evaluate(code, envir = env, new_device = FALSE, :
You changed the working directory to /Users/eruiz/Desktop/Stevens/Summer 2020/FE630 Portfolio Theory and Applications/Midterm/Summer 2020/Code (probably via setwd()). It will be restored to /Users/eruiz/Desktop/Stevens/Summer 2020/FE630 Portfolio Theory and Applications/Midterm/Summer 2020. See the Note section in ?knitr::knit
2: In in_dir(input_dir(), evaluate(code, envir = env, new_device = FALSE, :
You changed the working directory to /Users/eruiz/Desktop/Stevens/Summer 2020/FE630 Portfolio Theory and Applications/Midterm/Summer 2020/Code (probably via setwd()). It will be restored to /Users/eruiz/Desktop/Stevens/Summer 2020/FE630 Portfolio Theory and Applications/Midterm/Summer 2020. See the Note section in ?knitr::knit
3: In system2("tlmgr", args, ...) :
running command ''tlmgr' search --file --global '/xcolor.sty'' had status 1
Execution halted

Error in R while compiling the markdown

I am trying to save a xgboost code in Rmarkdown to knit HTML document. I am getting an error.
The code is completely executable in "R".
Fatal error: creation of tmpfile failed -- set TMPDIR suitably?
The error is same when I try to run knit Pdf/word.
Someone please help me.
Thank you
It seems the temporary directory cannot be created. Trying making your own temporary directory or setting it to the working directory:
Sys.setenv(TMPDIR = ".")

How to identify LaTeX errors in .Rd R help files? [duplicate]

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....
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.
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.
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:
https://www.ctan.org/tex-archive/fonts/inconsolata/?lang=en
https://www.ctan.org/tex-archive/macros/latex/contrib/upquote?lang=en
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.
...and another reason is that you haven't installed MikTex yet.
Download MikTex from here and follow the dialog prompts to install. I found the defaults to be reasonable and worked well for me.
Try to build your R package again. It should be OK now.
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
If you are on Ubuntu just install Tex Live by this command:
apt-get install texlive and restart Rstudo if you use it.
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")
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)

Resources