[R] Problem: Sweave and math environments

Christian Reisinger creisinger at gsss.uni-bremen.de
Tue Nov 4 12:16:16 CET 2008


Dear list,

I using R as the statistical package for my dissertation in political 
sciences and I am using Sweave for documenting the work done for the 
creation of my dataset. However, I have a problem with Sweave (which is 
great, by the way) which is (hopefully) easy to solve:

I want Sweave to "echo" my code, so that the R source code of the code 
chunks appears in the Latex document. However, since I am using several 
$ signs per line, as in the example line below, Latex interprets this as 
a math environment, despite the fact that the $ signs are within the 
{Sinput} environment. The problem now is that I sometimes have an 
unequal number of $ signs in an input line, so that LaTex thinks that 
all of the following "normal" text is still part of the math 
environment, and formats it accordingly.

This is an example input line:

Pre_Year <- MyMain3$Con_Stat[MyMain3$MyID==ID_Count[i] & 
MyMain3$MyYear==Count_Years[y-1]]

where I have three $ sings, and LaTex thinks that everything following 
the last $ sign is still part of a formula.

I have two question now:
1. Is there any way to solve the problem within Sweave itself, e.g. 
through setting options?
2. If not: is there a way to generally turn off the math mode in LaTex 
in the preamble, since I generally don't need it? (Maybe I should better 
post this in the LaTex mailing list, but maybe some people here had 
similar problems)

Thanks for all comments!
Best,
Christian

PS: I tried to replace all $ signs by \$, but this did not work either 
and caused many LaTex errors.

-- 
Ph.D. Candidate
Graduate School of Social Sciences
FVG-West
Wiener Straße/Ecke Celsiusstr.
28334 Bremen
Germany

Tel: +49 (0)421 218 4156

http://www.gsss.uni-bremen.de
creisinger at gsss.uni-bremen.de



More information about the R-help mailing list