RMarkdown not compiling into PDF - r

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

Related

Running R tikzDevice with tinytex: Help troubleshooting `! LaTeX Error: File `tikz.sty' not found`

I am trying to generate a tikz plot using R/ggplot2 via the tikzDevice package. I've had to wade through many errors as I figured out how to install R and tinytex on my docker image, but I've run into the following error which has simply stumped me.
When I run the code that generates my plot, this is the error I get:
Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) :
TeX was unable to calculate metrics for:
\char77
Run the following commands for diagnosis:
tikzTest()
tikzTest("\\char77")
Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.
The TeX and log files used for the calculation can help diagnose the
problem. If these files are missing, rerun the plot and make sure to
keep the R session open.
TeX file: tikzStringWidthCalc.tex
Log file: tikzStringWidthCalc.log
Calls: <Anonymous> ... descentDetails.text -> grid.Call -> <Anonymous> -> getMetricsFromLatex
Execution halted
And the output of tikzDevice::tikzTest() is as follows:
Active compiler:
/home/jovyan/.TinyTeX/bin/x86_64-linux/pdflatex
pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2021)
kpathsea version 6.3.3
Measuring dimensions of: A
Running command: '/home/jovyan/.TinyTeX/bin/x86_64-linux/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/tmp/RtmpLhckyy/tikzDevice29a5e00452e' 'tikzStringWidthCalc.tex'
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
TeX was unable to calculate metrics for:
A
Contents of TeX file tikzStringWidthCalc.tex:
\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage,psfixbb]{preview}
\PreviewEnvironment{pgfpicture}
\setlength\PreviewBorder{0pt}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\usetikzlibrary{calc}
\batchmode
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt, outer sep=0pt, scale=1] (TeX) {A};
\path let \p1 = ($(TeX.east) - (TeX.west)$),
\n1 = {veclen(\x1,\y1)} in (TeX.east) -- (TeX.west)
node{ \typeout{tikzTeXWidth=\n1} };
\end{tikzpicture}
\end{document}
Contents of log file tikzStringWidthCalc.log:
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex 2022.3.16) 16 MAR 2022 23:30
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**tikzStringWidthCalc.tex
(/tmp/RtmpLhckyy/tikzDevice29a5e00452e/tikzStringWidthCalc.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-02-24> (/home/jovyan/.TinyTeX/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/home/jovyan/.TinyTeX/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
)
\c#part=\count185
\c#section=\count186
\c#subsection=\count187
\c#subsubsection=\count188
\c#paragraph=\count189
\c#subparagraph=\count190
\c#figure=\count191
\c#table=\count192
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
! LaTeX Error: File `tikz.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name:
! Emergency stop.
<read *>
l.4 ^^M
Here is how much of TeX's memory you used:
235 strings out of 480236
3181 string characters out of 5895451
287032 words of memory out of 5000000
18278 multiletter control sequences out of 15000+600000
469259 words of font info for 28 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
34i,0n,38p,138b,36s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
As you can see I am using tinytex, but I have installed the recommended packages for this setup as described in the tinytex documentation (i.e., I've already ran tlmgr install pgf preview xcolor).
I've read every post I could possibly find on this subject but am coming up empty. Any tips to help me troubleshoot this problem would be greatly appreciated.
it would help if you had a minimum reproducible example to check on our end.
This said, the message LaTeX Error: File `tikz.sty' not found. suggests that a possible solution would be for you to throw:
library(tinytex)
tlmgr_search('/tikz.sty') # search for tikz.sty
tlmgr_install('pgf') # install the psnfss package
tlmgr_update() # update everything
since tlmgr_search('/tikz.sty') gives you
tlmgr search --file --global "/tikz.sty"
tlmgr.pl: package repository https://ctan.mirror.garr.it/mirrors/ctan/systems/texlive/tlnet
pgf:
texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
but then you already installed pgf... that's where tikz.sty lives.

How to build API documentation for an R package in RStudio?

I'm working on a very recent Windows 10 build, RStudio 1.3.959 and I've just installed the latest MikTex.
I'm trying to put together an R package using RStudio. I can build the package and the Function documentation comments are being converted into /man/*.Rd files. These are then successfully displayed when one executes ?function_name in the RStudio console window.
Unfortunately, I'm having very little luck building the PDF package API documentation (not to be mistaken as the vignette; which I can build). I've looked over a good few tutorials but they all stop short of instructing how one builds the final PDF API document that one expects with every R package.
I've tried:
Build[Windows]->More->Document ... which execute devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))
Build[Windows]->More->Build Source Package ... which executes devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette')) followed by devtools::build(binary = TRUE, args = c('--preclean'))
Build[Windows]->More->Build Binary Package ... which executes devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette')) followed by devtools::build(binary = TRUE, args = c('--preclean'))
All three function as expected but still no final package manual pdf file.
Doing some digging on Stack I noticed someone used the command:
devtools::build_manual()
I'm convinced this is what I need. However, when I execute that line of code I get the error:
Converting Rd files to LaTeX ...
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'
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()
Error: Failed to build manual
Which has left me none the wiser, although it's quite clear that something's a bit upset by the absence of makeindex. Help is much appreciated.
If I understand correctly, you mean the standard reference manual. For example ggplot2 reference manual. In my experience, this is thrown together by CRAN when you submit. All the manual is (as far as I can tell) a collection of things that a well documented package should have, such as a DESCRIPTION file, a NAMESPACE file, and the various .RD files for actual documentation.
Even when looking at the public github for ggplot2 we see that they do not have the manual in their repository. Additionally, there isn't any evidence in their .git*ignore files to suggest they made the manual themselves.
However, if you want to make this yourself devtools::build_manual() is the correct function call.
I was able to make the manual with a preexisting package on github. I would suggest trying to reinstall your devtools package and make sure there are no warnings or errors. It may be helpful to run a session as administrator to insure things get installed correctly.
Good luck!
I am using R version 3.4 with RStudio 1.1.453 on MacOS High Serra.

Can't understand the error message from blogdown

I am trying to make a blog with blogdown using my windows machine, but get this error message when I use RStudio (File/New Project/New Directory/Website using blogdown/ ... and enter Directory name: "new"):
setwd("C:/Users/AndrésLagerlöf/OneDrive - Andrés Lagerlöf Konsulttjänst AB/R/blog")
'C:\Users\Andr‚sLagerl”f\AppData\Roaming\Hugo\hugo.exe" new site "new' is not recognized as an internal or external command,
operable program or batch file.
Error in shell(cmd, mustWork = TRUE, intern = intern) :
'"C:\Users\AndrésLagerlöf\AppData\Roaming\Hugo\hugo.exe" new site "new" --force -f toml' execution failed with error code 1
I do not know what to make out of this error message. Does anyone know how to fix this?
I use R version 4.0.0 and RStudio Version 1.2.5033.
Kind regards,
Andrés
You may consider installing Hugo to a path that does not contain multibyte characters. Per documentation ?blogdown::install_hugo:
If you want to install Hugo to a custom path, you can set the global option blogdown.hugo.dir to a directory to store the Hugo executable before you call install_hugo(), e.g., options(blogdown.hugo.dir = '~/Downloads/hugo_0.20.1/').
This is also mentioned in Appendix D.1 in the blogdown book. You'd better set this option in your .Rprofile (see Section 1.4 for how), so the setting won't be lost after you restart R.

I can't knit my documents into PDF in RStudio

I have to use RStudio to knit a report in PDF but when I try to knit the document with the packages required in a chunk in Rmarkdown it shows me this error:
tlmgr search --file --global '/multirow.sty'
tlmgr: Remote repository is newer than local (2018 < 2019)
Cross release updates are only supported with
update-tlmgr-latest(.sh/.exe) --update
Please see https://tug.org/texlive/upgrade.html for details.
! LaTeX Error: File `multirow.sty' not found.
! Emergency stop.
<read *>
Errore: Failed to compile questionario_sulla_responsabilita_222222.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See questionario_sulla_responsabilita_222222.log for more info.
Inoltre: Warning message:
In system2("tlmgr", args, ...) :
running command ''tlmgr' search --file --global '/multirow.sty'' had status 1
Execution interrupted
how can I fix this? I am using a MacBook Pro
I tried to updated everything I can and I've tried to install everything from the beginning but it jeeps showing me the same error message
To wrap the comments to the question up and following the solution at Yihui Xie's page - see also here for a discussion.
In short ...
tinytex::reinstall_tinytex()
... should do the trick.
Explanation: It seems that {tinytex}/Texlive is using a rolling package repository that moves to a new version each year while the local installment does not. The reinstallation does move the local installment forward.
An alternative solution: There seems to be an alternative solution that involves making the TexLive package repo un-rolling - i.e. using a fixed version - which might help: link

knit2pdf failing to produce pdf in Shiny Apps

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.

Resources