The way to automatically exit characters ('_', '\', etc.) Using knitr

I am using Rstudio under Win7. Is there a way a scribe automatically avoids a character? Below is 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 need to change everything '_' to '_' in my tex file. Is there any way to do this directly in the sweave file. I would appreciate any suggestion on this ...

+3
source share
1 answer

I think you want to put the name in a shorthand environment, and not in a mathematical environment:

 \verb|\Sexpr{names(df1)}| 
+7
source

Source: https://habr.com/ru/post/1492528/


All Articles