3

I m using Rstudio under Win7. Is there a way that knitr automatically escape a character? Please see below for a simpler example:

\documentclass[a4]{article}
\title{Example}
\author{Stat-R}

\begin{document}

\maketitle

<<nothing,echo=FALSE>>=
my_name <- 'hari'
my_number <- 100

df1 <- data.frame(my_name,my_number)
df1
# names(df1)
@

\section{Testing only}

Now I will print the columnnames of my data frame df1
$\Sexpr{names(df1)}$

\end{document}

I get the following output...

enter image description here

But I want the following

enter image description here

I will have to change all '_' into '_' in my tex file. Is there a way to directly do it in sweave file. I will appreciate any suggestion on this regard...

Stat-R
  • 5,040
  • 8
  • 42
  • 68
  • I haven't used knitr in a while but do you need the $ $ around the \Sexp{}? I don't think you do and that seems to be what is causing your problems. – Dason Mar 27 '12 at 20:18
  • Without the $ $ around, the program does not even compile..I may be missing something... – Stat-R Mar 27 '12 at 20:54

1 Answers1

7

I think you want to put the name in an verbatim environment rather than a math environment:

\verb|\Sexpr{names(df1)}|
Sacha Epskamp
  • 46,463
  • 20
  • 113
  • 131