My question is the same as the one in the link Sweave syntax highlighting in output.
I have followed the suggestion by daroczig https://tex.stackexchange.com/questions/5113/how-to-colorize-syntax-using-r-sweave, and created the following test.Rnw file:
\documentclass{article}
\RequirePackage{fancyvrb}
\RequirePackage{listings}
\SweaveOpts{keep.source=TRUE}
<<SweaveListingsPreparations, results=tex, echo=FALSE, strip.white=false>>=
require(SweaveListingUtils)
SweaveListingPreparations()
setToBeDefinedPkgs(pkgs = c("SweaveListingUtils","distr"),
keywordstyles = c("\\bf\\color{blue}","\\bf\\color{red}"))
@
\begin{document}
\SweaveOpts{concordance=TRUE}
\section{Example}
This is an example with three variables in R.
<<>>=
options(continue = " ")
x <- 10
t <- 'The brown fox'
b <- TRUE
@
<<>>=
x
@
<<>>=
t
@
<<>>=
b
@
\end{document}
<<cleaup, echo=FALSE>>=
unloadNamespace("SweaveListingUtils")
@
However, I get the following error message:
Suggestions?
Since you don't have
\usepackage{Sweave}
in your document, Sweave will insert it. But theSweaveListingsUtils
package also inserts conflicting code.So you need to follow the advice in the
SweaveListingsUtils
documentation, and put in a commentnear the start of your document. This will prevent R from inserting it.
However, do note that support for
SweaveListingsUtils
is ending; you are better off usingknitr
.