I'm new to knitr and to Latex.
I keep getting the error "! LaTeX Error: File `figure/unnamed-chunk-1' not found." The error message says:
>! LaTeX Error: File `figure/unnamed-chunk-1' not found.
> See the LaTeX manual or LaTeX Companion for explanation.
> Type H <return> for immediate help.
...
> l.77 ...[width=\textwidth]{figure/unnamed-chunk-1}
> I could not locate the file with any of these extensions:
> .png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPEG,.JBIG2,.JB2,.eps
I have a simple tex file
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[font={small}]{caption}
\author{My Name }
\title{knitr example}
\begin{document}
\maketitle
<<loading,echo=F>>=
library(ggplot2)
#
<< message=F,fig.width=9,fig.height=6,out.width='\\textwidth',cache= TRUE>>=
mydata <- data.frame(year = seq(1901: 1950), debt = rnorm(50))
plot(mydata$year, mydata$debt, main = "Debt")
#
\end{document}
I cannot seem to locate anything that seems relevant. Clearly "figure/unnamed-chunk-1" should be showing up somewhere but I don't see anything in the knitr options document to suggest a specific way to save it and so far I don't understand enough about knitr to figure out a way to name a plot to be imported.
It has been solved in the knitr mailing list. The problem was due to use of absolute paths in the output argument in knit(), so figures and tex output were not in the same directory. It is not recommended to use absolute paths in general; see more discussion in the mailing list.
An old question, but it I stumbled the issues recently, whether on MacOS or Win. I have tried the solution above but didn't work. What works for me is to delete all the figure inside figure-latex folder and re-run the knit.
Related
I have a similar problem as already described, but the answers do not help me, that is why I am writing one more post.
I try to compile a tex file (a standard example from the web) in R, but R cannot file the pdflatex file:
Error running C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code 1)
I tried
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex", sep=.Platform$path.sep))
or
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex", sep=.Platform$path.sep))
(if I am wrong with the syntax), but no effect.
I added a Renviron.site file in the respective directory, writing this in it:
PATH=C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex;"${PATH}"
but no effect. When I write
Sys.getenv("PATH")
I get something strange:
Sys.getenv("PATH")
[1] "C:\\Users\\vica\\Documents\\R\\R-4.0.3\\bin\\x64;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Users\\vica\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\;C:\\Users\\vica\\AppData\\Local\\Programs\\Python\\Python39\\;C:\\Users\\vica\\anaconda3;C:\\Users\\vica\\anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\vica\\anaconda3\\Library\\usr\\bin;C:\\Users\\vica\\anaconda3\\Library\\bin;C:\\Users\\vica\\anaconda3\\Scripts;C:\\Users\\vica\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\vica\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\vica\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\vica\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\;C:\\Users\\vica\\AppData\\Roaming\\TinyTeX\\bin\\win32;C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex"
>
I tried to compile the sweave file (exa3.tex), this is what I got:
Writing to file exa3.tex Processing code chunks with options ... You can now run (pdf)latex on 'exa3.tex'
Running pdflatex.exe on exa3.tex...failed Error running C:/Users/vica/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791
But when I KNIT the Rnw file, I get the pdf. This is my exa3.Rnw:
---
title: "MyFile1"
author: "Victoria"
date: "6 5 2021"
output: pdf_document
---
## R Markdown
Hello, World!
This is my tex file:
\documentclass[a4paper]{article}
\SweaveOpts{concordance=TRUE}
\title{Sweave Example 1}
\author{Victoria Knopova}
\usepackage{Sweave}
\begin{document}
\maketitle
In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:
\end{document}
Maybe I do something entirely wrong when I compile *.tex files, but I do not understand what, I only learn R...
Can somebody help me?
Thank you in advance.
Victoria
**PS: I found another way: one can use this hint
Rmarkdown to LaTeX
in order to translate a *.Rmd file to *.tex
**
This question already has answers here:
Rstudio pdf knit fails with "Environment Shaded undefined" error
(5 answers)
Closed 4 years ago.
I am creating a report using the rticles package and I get the following error when knitting an rticle IEEE paper which includes code-chunks:
output file: rticles_IEEE.knit.md
! LaTeX Error: Environment Shaded undefined.
I tried to understand how to fix the issue and played around with this question/answer. But I fail to see where to put the fix into the files created by knitting (e.g. mydoc.tex, IEEE_trans.cls).
Here is my minimal example:
---
title: Cool IEEE ArticleS
author:
- name: Ray
abstract: |
The abstract of my first IEEE paper with rmarkdown
output: rticles::ieee_article
---
Introduction
=============
This is the introduction. And here comes a cool code chunk.
```{r}
x <- seq(-3,3,0.1)
y <- x^3
plot(x,y)
```
Notes:
It was commented that this is a potential duplicate of another question. The problem with the answers given in that thread is that it does not explain where to make the changes.
I fail to understand the pointer to Yihui's fix.
The aforementioned files, but also the knitted .tex does not come with labels of the form \makeatother or \makeatletter.
The overall issue was that displaying a code chunk in the rticles IEEE paper throws an error pointing at the undefined Shaded environment.
The solution given in the older post works, if you add the following to the underlying LaTeX template.tex. My problem was that I tried to edit the tex or cls template in the working directory. The Eureka-moment came when I stumbled over the following (related) stackoverflow question.
For the rticles package, the template.tex is not located in your directory you work on the article R Markdown file. Instead, they are stored within the package library folder (i.e. the folder that .libPaths() uses). The file can be found in rmarkdown/templates/ and search for the rticles folder you are using (in my case: ieee_article). In the resources sub-folder you will find the target template.tex. Make a copy of it, for recovery purposes.
Open the template.tex and insert the following anywhere before the LATEX command line \begin{document} (note: aka the preamble of that template.tex file). For example, I inserted it just before the \begin{document} line:
% code to insert to fix environment Shaded undefined issue with
% showing code chunks in rticle IEEE template.
$if(highlighting-macros)$
$highlighting-macros$
$endif$
\begin{document}
Save the change and go back to R/RStudio and your IEEE paper R Markdown file and hit the knit button. R code chunks will now be displayed (if you want to).
I have not tested it thoroughly, but this recipe should work for all rticle templates missing an environment definition for showing r-code chunks (i.e. environment{Shaded})
Rather than duplicating the template, you can put the required code for allowing the highlighting in a separate header.tex file. This is essentially what replaces $highlighting-macros$ when you include this in the template:
header.tex
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
Make a copy of this file in your directory and then refer to this header in the YAML:
---
title: Short Paper
output:
rticles::ieee_article:
includes:
in_header: header.tex
---
# Introduction
This is the introduction. And here comes a cool code chunk.
```{r}
x <- seq(-3,3,0.1)
y <- x^3
plot(x,y)
```
This approach should work for any template which includes the $header-includes$ tag in thetemplate.tex`
I have tried to attach bibliography.bib, nature.csl files by using knitcitations packages on myPkg_vignette.Rmd, but when I execute the .Rmd file, I got following error:
pandoc-citeproc.exe: Could not find bibliography.bib
pandoc.exe: Error running filter pandoc-citeproc
Filter returned error status 1
Error: pandoc document conversion failed with error
I looked into knitcitations manual and how to attach .csl, .bib file by handy, but I got warning and can't attach these files on myPkg_vignette.Rmd.
Edit :
This is context of bibliography.bib:
#article{Vahid_Jalili_Musera_2015,
title = "MuSERA: Multiple Sample Enriched Region Assessment",
author = {Vahid Jalili, Matteo Matteucci, Marco Masseroli, Marco J. Morelli},
journal = "Briefings in Bioinformatics",
year = "2016",
pages = "1-15",
url = {http://bib.oxfordjournals.org/content/early/2016/03/23/bib.bbw029.abstract?keytype=ref&ijkey=8IlROGziM9XA7NS},
doi = "10.1093/bib/bbw029 ",
}
How can I attach bibliography.bib, nature.csl on package's vignette easily ? I read some post in SO and I confused about the given solution. I am quite new with using knitcitations packages, and I may get wrong with attaching .bib, .csl files in right way. Can any one help me out how to address this issues in Rstudio ? Any idea ? Thanks a lot :)
NEW EDIT :
I've read this post and followed the solution :
setwd('C:/Users/me/Documents/myPkg')
Sys.setenv(TEXINPUTS=getwd(),
BIBINPUTS=getwd(),
BSTINPUTS=getwd())
but bibliography.bib is not printed in .Rmd file. I changed the global option for weaving Rnw file to knitr. How can I print out bibliography on .Rmd file ? Any further help please ?
As with Dirk, it just works for me. Maybe you didn't put the YAML together properly, or maybe you never cited anything. Here's a sample document that works with your bib file:
---
title: "Biblio Example"
output: html_document
bibliography: bibliography.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Here's Some Text
This text cites the paper: [#Vahid_Jalili_Musera_2015].
## References
The bibliography will appear by magic at the end of the document, just
below this text.
See http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html for more details.
For me the problem was that my .bib file was listed in .Rbuildignore. Removing the entry solved the problem.
According to the r-pkg-dev mailing list answer from Duncan Murdoch, .Rbuildignore is "case-insensitively against the file and directory names relative to the top-level package source directory".
Therefore the entry xxx.bib ignored all .bib files recursively in my package directory and the error was thrown.
I can't seem to hack my way through all the possibilities and have a full bibliography inserted in the PDF output of RStudio, knitr, an .Rnw script, and the "Compile PDF" button. The desired text in the PDF would be the details of the cited works.
Here is a Lilliputian bibtex file, called jabrefbibtest.bib, saved in the working directory.
#Book{GreentargetEngagement2012,
Title = {"2012 - In - House Counsel New Media Engagement Survey"},
Author = {"Inside Counsel "},
Publisher = {"Greentarget"},
Year = {"2012"},
Pages = {"20"},
Plots = {"9"},
Tables = {"0"},
Url = {"http://www.greentarget.com/wp-content/uploads/2012/01/2012GTZGICSurveyReportFinal-WebsiteVersion.pdf"}
}
#Book{CitiprivateBank,
Title = {"Intellectual Leadership with Law Watch"},
Author = {""},
Publisher = {""},
Year = {"2008"},
Pages = {"2"},
Plots = {"1"},
Tables = {"4"},
Url = {"http://www.citigroup.com/privatebank/lawassociates/pdfs/lawwatch/slipsheet.pdf"}
}
The .Rnw script, stripped down, is
\documentclass[11pt]{article}
\usepackage[backend=bibtex]{biblatex}
% \addbibresource{} # not sure if this is needed
\begin{document}
<<bibbackground, echo=FALSE, include=FALSE>>=
setwd("~/R/knitr docs/")
Sys.setenv(TEXINPUTS=getwd(),
BIBINPUTS=getwd(),
BSTINPUTS=getwd())
#
\bibliographystyle{plain}
\bibliography{jabrefbibtest}
Here is one citation \cite{GreentargetEngagement2012} and here is a second \cite{CitiprivateBank}.
Now do full References show below?
\printbibliography
\end{document}
The log:
! Package biblatex Error: '\bibliographystyle' invalid.
See the biblatex package documentation for explanation.
Type H <return> for immediate help.
...
l.59 \bibliographystyle{plain}
Use the package option 'style' instead.
I'm ignoring this command.
! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.60 \bibliography
{jabrefbibtest}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
LaTeX Warning: Citation 'GreentargetEngagement2012' on page 1 undefined on inpu
t line 62.
[more omitted]
Along with The Latex Companion, Dynamic Documents with R and knitr, by Yihui Xie, two LaTeX primers and the 262-page manual for biblatex I have struggled through the complicated advice of these sites. Fruitlessly.
https://tex.stackexchange.com/questions/71565/knitr-and-biblatex
https://tex.stackexchange.com/questions/63852/question-mark-instead-of-citation-number
http://texblog.org/2013/08/20/rknitr-automatic-bibliography-generation-with-biblatex-in-rstudio/
http://www.inside-r.org/packages/cran/knitcitations/docs/bibliography
EDIT after COMMENTS
All the PDF file has is this:
References
Here is one citation [?] and here is a second [?].
Now do full References show below?
As the error messages told you:
Don't use \bibliographystyle{plain} (this does not work for biblatex); use the style option in \usepackage[]{biblatex} instead;
\bibliography{jabrefbibtest} must be put in the preamble instead of the body.
After you correct these issues, it should work:
\documentclass[11pt]{article}
\usepackage[backend=bibtex]{biblatex}
\bibliography{jabrefbibtest}
% or use \addbibresource{jabrefbibtest.bib}
\begin{document}
Here is one citation \cite{ABFWomenFirstChairs2015} and
here is a second \cite{ACCGCSkills2013}.
Now do full References show below?
\printbibliography
\end{document}
BTW, RStudio probably does not support the default backend biber of biblatex, so the backend=bibtex option was used.
I use exactly this setup below to get (note I'm not a fan of changing wd in knitr/rmarkdown and removed this; also your keys in the Rnw didn't match the key in the mwe):
\documentclass[11pt]{article}
\usepackage[american]{babel}
\usepackage[style=apa,backend=biber,bibencoding=latin1]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{jabrefbibtest.bib}
\begin{document}
<<bibbackground, echo=FALSE, include=FALSE>>=
#setwd("~/R/knitr docs/")
Sys.setenv(TEXINPUTS=getwd(),
BIBINPUTS=getwd(),
BSTINPUTS=getwd())
#
%\bibliographystyle{plain}
Here is one citation \cite{GreentargetEngagement2012} and here is a second \cite{CitiprivateBank}.
Now do full References show below?
\printbibliography
\end{document}
Also after the Rnw knits I have to run the tex file though a LaTeX compiler to render the references the first time.
I always just place \bibliography{jabrefbibtest} at the end of the script where I want the references to occur.
To include all references from your .bib file in your bibliography, i.e. even ones that you didn't end up citing, include the line
\nocite{*} right before the line \printbibliography
I am trying to render a pdf document with the knit pdf button in RStudio, but I keep on getting this error:
! pdfTeX error (font expansion): auto expansion is only possible with scalable
fonts.
\AtBegShi#Output ...ipout \box \AtBeginShipoutBox
\fi \fi
l.167
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
I know there is a lot be found on the internet regarding error 43, but non of them helped me.
Does anyone know what it means exactly and where I can find the solution? It's peculiar because a few hours ago I had the same error but the rendering went well after adding this in my code:
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\", sep=.Platform$path.sep))
But now the error is back
EDIT
when trying a minimal example:
---
title: "test"
output: pdf_document
---
```{r results="asis"}
library(stargazer)
c1 <- c("test1","test1","test2","test2")
c2 <- c(1,2,3,4)
data_object <- as.data.frame(cbind(c1,c2))
names(data_object) <- c("test","test2")
stargazer(data_object,summary=FALSE,rownames=FALSE,type="html")
```
The error it gives is:
!pdfTeX error: pdflatex (file ec-lmr10): Font ec-lmr10 at 600 not found
==> Fatal error occurred, no output PDF file produced!
Trying to make PK font ec-lmr10 at 600 DPI...
Running miktex-makemf.exe...
miktex-makemf: The ec-lmr source file could not be found.
miktex-makepk: The application file ttf2pk.exe could not be found.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
This is a different error, but still a 43 one. I checked it, but the font ec-lmr10 file is on the system. Somehow it can't be found.
The problem you have is a font related one. When you knit a PDF, knitr uses LaTeX and you have to know that "fonts" of LaTeX are not like the standard ones.
To solve your problem try to add the latin model font family by loading the package (at the very top):
\usepackage{lmodern}
For more detailed informations about how and where insert this piece of code in your document, have a look here.
This package allows you to have scalable fonts; not all fonts of all (font) packages are to so.
I think, but I might be wrong, because first versions of TeX and LaTeX were designed to work with METAFONT.
Edit
Your code works well for me, it does not produce any error. My idea is that happens because I have a complete Tex live distribution on my Mac (MacTeX). At this point I suppose that the problem relies on some packages that the r packages you use (like stargazer) use and you (we) do not know and won't (unless we analyze the code of course).
At this point my suggestion is to download a complete TeX distribution so you will be sure that any error related to PDF output is no related to the underlying tool that Studio uses to produce such PDFs (say, LaTeX).
You can find a complete LaTeX distribution for Mac and for Windows.