[R] Sweave: \Sexpr and variables with special chars

Ralf B ralf.bierig at gmail.com
Tue Nov 16 20:54:48 CET 2010


I am using \Sexpr to include a variable in a title of a Sweave document:

\documentclass[a4paper]{article}
<<echo=false, results=hide>>=
#mytitlevar <- "Stuff" # case 1, everything is find
mytitlevar <- "Stuff_first" # case 2, f is turned into sub-text
@
\title{MyTitle: \\ \Sexpr{mytitlevar} }
\begin{document}
\maketitle
\end{document}

When doing this, the variable seems to be subject to interpretation by
LaTeX. The variable in case #2 causes the 'f' of 'Stuff_first' to be
printed as sub-text because of the leading underscore. Is there a way
to turn the variable value (the text) into a form so that it is not
interpreted and/or Sweave? I understand that this perhaps more of a
LaTeX question than an R question...

Thanks,
Ralf



More information about the R-help mailing list