I am using R markdown to knit a paper of mine, and R markdown does not knit
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
(\#eq:binom)
\end{equation}
it would knit
$\phi _ { k }$.
In conclusion, it does not recognize \begin..\end
any ideas? Thank you!
I am not getting any error messages, and the code used to work in rnw file.
Related
I had trouble position exactly my plots and figures when knitting to pdf a R Markdown document with knitr.
This question helped me: https://community.rstudio.com/t/cant-control-position-of-tables-and-figures-in-knitted-pdf-document/37364 , where the answerer uses a text file to fit in the latex instructions for the knit.
I am trying to knit the following code, that works perfectly on my console, in an R markdown file. However, I can't knit it because the function scores isn't recognized (part of the package outliers, which is correctly installed). Any ideas on how to knit something from a downloaded package?
Thank you!
I am trying to print a long code, highlighted with R syntax, at the end of my thesis, written in R markdown. I am knitting to pdf. I receive the error: ! Dimension too large.
I am copy pasting my code into the document:
```R
Pasted code
```
I was wondering if there is a way to avoid the error when printing my code in R markdown.
I'm trying to insert LaTeX code into a figure caption created by knitr. I have the code below in a .Rnw file and I'm converting it to a .tex file using knitr:
<<my_plot, fig.cap="X is $\leq$1 and Y is $\geq$2">>=
plot(1,2)
#
Code as it stands give an error. How can I use insert the LaTeX code into the figure caption?
I'd like to use a Knitr/Sweave in-line call (\Sexpr{}) in the title of a LaTeX document, after the \begin{document} command but before the \maketitle command. The in-line R code would extract one or two pieces of information from an R data-frame created early in the R script I'm embedding in LaTeX.
I have a couple of Knitr chunks that create a data.frame from which I derive the information I want to put in the Title. I've tried placing these chunks between LaTeX's \begin{document} call and the \title code, like this:
\documentclass
[LaTex Preamble]
\begin{document}
[%% Knitr chunks that initialize an R data-frame]
\title \Sexpr{--a snippet of R code that extracts an element from the data-frame --}
\maketitle
... (rest of the LaTeX document)
and I've also tried putting the Knitr chunks in the preamble to the LaTeX code before \begin{document} statement.
But in Knitr seems to ignore code (other than initialization) that is placed ahead of the \maketitle call in LaTeX, so the in-line snippets included the title look like errors to Latex and it halts output.
I can't find any information in the Knitr documentation on including in-line code in the Title of a LaTeX document.
Any ideas?
OK: Found the solution thanks to the hint from #ben-bolker below. Ben uses the formatting of R chunks before output to an RNW file (in a 2-step Knitr process: latex -> rnw -> pdf) . But I'm compiling the LaTeX file to PDF in one-step without going to an RNW file from inside TeXShop (on Mac OSX). I found that I could get Ben's example to work using the RNW delimiters (<<>>=) and one-step compiling. But I couldn't mix the usual LaTeX chunk-delimiters (%%begin.rcode and %% end.rcode) and the RNW in-line statement hook (\Sexpr{}). The latter didn't work no matter how I fiddled with it. Eventually I found that the correct in-line hook for LaTeX is \\rinline{}.
It's not very clear in the Knitr documentation that this is the required format for LaTeX and I found it eventually mainly thanks to Ben's example. Best, Peter
Update 2 ... and then there's RTFM (or the 'cheat sheet' in this case): http://cran.r-project.org/web/packages/knitr/vignettes/knitr-refcard.pdf
Hmm. The following file works for me:
\documentclass{article}
<<echo=FALSE>>=
x <- 5
#
\title{The number is \Sexpr{x^2}}
\begin{document}
\maketitle
Some stuff
\end{document}
with knitr version 0.8 on Ubuntu 10.04, via knit2pdf("knitr_title.Rnw") ...