I am looking for a way to put inline latex code into a R code chunk in Knitr. Here is my example code from the knitr example site :
\documentclass{article}
\begin{document}
Example text outside R code here; we know the value of pi is \Sexpr{pi}.
<<my-label, echo=FALSE, eval=TRUE>>=
set.seed(1213) # for reproducibility
x = cumsum(rnorm(100))
m <- mean(x) # mean of x
print(m)
cat(m)
plot(x, type = 'l') # Brownian motion
@
\textit{Mean is :} \textbf{\Sexpr{m}}
\end{document}
For something simple like this is I could use result='asis'
but for a more complicated piece of code, where you want to periodically write the result out to the document, (especially you have complex ggplot graphs), that solution does not work very well.
In the given example, I have 3 queries :
- How would I use inline latex code for the output from line 8, in case I wanted to color, bold etc. that text.
- Can one eliminate the grey box that appears when we use the
cat
orprint
command. - Can the numbering which appears with the
print
command, which is eliminated with thecat
command be eliminated for theprint
command as well, sinceprint
has many variants in many packages for data frames data tables etc. and might be more commonly used to print a portion of data.
In summary, I am mainly looking for the inverse of line 12 in the code.
I have also unsuccessfully tried knit_print
with printr
, and asis_output
, in lieu of print. Although I may have been incorrectly using them.
Thanks!