我正在尝试使用R的Brew包编写报告.我首先采用了这个网页上的一些代码http://learnr.wordpress.com/2009/09/09/brew-creating-repetitive-reports/
我可以使用brew为这样简单的东西制作一个PDF-able Tex文件:
documentclass[11pt]{amsart}
\begin{document}
<% library(xtable); library(ggplot2) %>
<% for (i in 1:2) { %>
<%=print(i) %>
<% } -%>
\end{document}
Run Code Online (Sandbox Code Playgroud)
但如果我尝试插入一个简单的cat命令:
documentclass[11pt]{amsart}
\begin{document}
<% library(xtable); library(ggplot2) %>
<% for (i in 1:2) { %>
<%=cat("\section{", i, "}", sep="") %>
<% } -%>
\end{document}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
brew("Brew/test_brew3.brew", "Brew/test_brew2.tex")
Error: '\s' is an unrecognized escape in character string starting "\s"
Run Code Online (Sandbox Code Playgroud)
什么可能出错?在上面的帖子中调用\ section命令,所以我想知道它是否与我的R环境有关?
你的问题与brew无关.您可以通过调用以下方法复制错误:
cat("\section{", i, "}", sep="")
Run Code Online (Sandbox Code Playgroud)
如果你需要一个文字\
,你必须逃避它:
cat("\\section{", i, "}", sep="")
Run Code Online (Sandbox Code Playgroud)
经验教训是,不断尝试复制错误,直到达到最低限度可重复的形式.或者从命令的最基本部分开始,添加组件直到发生错误.