Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R and Brew:syntax issue

Tags:

r

latex

I am trying to use R's Brew package to write a report. I am starting by adopting some of the code from this webpage http://learnr.wordpress.com/2009/09/09/brew-creating-repetitive-reports/

I can use brew to make a PDF-able Tex file for something simple like this:

documentclass[11pt]{amsart}
\begin{document}

<% library(xtable); library(ggplot2) %>
<% for (i in 1:2) { %>
<%=print(i) %>

<% } -%>

\end{document}

but if i try to insert a simple cat command:

documentclass[11pt]{amsart}
\begin{document}

<% library(xtable); library(ggplot2) %>
<% for (i in 1:2) { %>
<%=cat("\section{", i, "}", sep="") %>

<% } -%>

\end{document} 

i get the following error:

brew("Brew/test_brew3.brew", "Brew/test_brew2.tex")
Error: '\s' is an unrecognized escape in character string starting "\s"

Any thoughts about what might be going wrong? the \section command is called in the post above so I am wondering if it is something with my R environment?

like image 248
zach Avatar asked Oct 14 '11 00:10

zach


1 Answers

Your problem has nothing to do with brew. You can replicate the error by calling:

cat("\section{", i, "}", sep="")

If you need a literal \, you must escape it:

cat("\\section{", i, "}", sep="")

The lesson is, keep trying to replicate the error until you get to its minimally reproducible form. Or start with the most basic portion of the command and add components until the error occurs.

like image 61
Joshua Ulrich Avatar answered Oct 12 '22 00:10

Joshua Ulrich