Problem description
I'm using knitr in the environment of Overleaf and want to include an externally saved image.
Previous attempts
EDIT: At the moment all the attemps give a compile error and an emergency stop: '<*> main.tex ***(job aborted, file in nonstop mode)'. So I suspect a general problem in the code, but I cannot spot it.
Here is what I already tried:
- Uploading the image to Overleaf and calling it outside a knitr chunk with a default:
\begin{figure}[htbp]
\includegraphics{image.png}
\end{figure}
- Inpired by this post, saving the image in a variable inside a knitr chunk and including the graphic outside the chunk:
<<fig1,fig=TRUE>>=
f='path/to/image.png'
@
\includegraphics{\Sexpr{f}}
Download to the image: RPBU 2011 6 highest peaks 1 & 2
Minimal Working example (MWE):
Please notice that other tries than the first need to be uncommented first.
\documentclass{article}
\begin{document}
<<standardsettings,echo=FALSE,results='hide'>>=
%%begin novalidate
library(knitr)
opts_chunk$set(echo=FALSE,fig.width=10,fig.height=5,fig.align='center')
@
%%end novalidate
%First try: Uploading to overleaf and calling outside knitr chunk:
\begin{figure}[htbp]
\includegraphics[width=\linewidth]{RPBU11hp12.png}
\end{figure}
%Second try: Saving image in variable inside knitr chunk and including graphic outside chunk
%<<fig:6highpeaks2018, fig = TRUE>>=
%RPBU11hp1&2 = 'C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png'
%@
%\begin{figure}[htbp]
%\includegraphics[width=\linewidth]{\Sexpr{RPBU11hp1&2}}
%\end{figure}
%Third try: Directly including the image inside the chunk
% %%begin novalidate
%<<fig:highpeaks2018, fig = TRUE>>=
%knitr::include_graphics(path = %"C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png")
%@
% %%end novalidate
%Fourth try: Other method of directly including the image inside the chunk
%<<fig:6highpeaks2018, fig = TRUE>>=
%<img src="C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png" width="50%"/>
%@
\end{document}