使用knitr自动转义字符("_","\"等)的方法 [英] Way to automatically escape characters ('_','\' etc) using knitr
本文介绍了使用knitr自动转义字符("_","\"等)的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在Win7下使用Rstudio.编织器是否可以自动转义字符?请参见下面的简单示例:
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}
我得到以下输出...
但是我想要以下
我将不得不在我的tex文件中将所有的'_'更改为'_'.有没有一种方法可以直接在sweave文件中执行此操作.我会很高兴就此提出任何建议...
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...
推荐答案
我认为您想将名称放在逐字记录环境而不是数学环境中:
I think you want to put the name in an verbatim environment rather than a math environment:
\verb|\Sexpr{names(df1)}|
这篇关于使用knitr自动转义字符("_","\"等)的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文