Pass underscore as inline code to knitR

谁说胖子不能爱 提交于 2019-12-08 18:31:32

A suitable work around is to define the function rep_ in the code block. rep_ just looks for the underscore and places a "\" before it.

\documentclass{article}
\begin{document}
<<>>=
data.df = data.frame(var_name_1=c(0,1),var_name_2=c(1,2))
rep_ = function(test){gsub("([_])", '\\\\\\_', "test_var")}
@
I want to be able to print \Sexpr{rep_((names(data.df)[1]))} and \Sexpr{rep_((names(data.df)[2]))} normally.

\end{document}

Resulting in what we want!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!