In tables that are generated have the character after the subscript
subscripted, as opposed to being displayed as desired (see pg 4 of
example output at
http://slack.ser.man.ac.uk/files/genetic_analysis.pdf , please ignore
the table on pg 3, as I said I'm just starting :-).
After googling and searching R-help archives didn't reveal any obvious
problems with this (other than in older versions of R underscores were
not allowed in variable names).
My question is, other than the obvious of renaming my variables, or
manually editing the .tex file that Sweave produces, is there any way
to have variable names with underscores correctly represented in the
resulting tex file?
Re: Sweave - problems with underscores in variable names...
On Thu, 16 Feb 2006, Neil Shephard wrote:
> Hi all,
> I've just started using the Friedrich Leisch's Sweave package to
> generate LaTeX reports with results of my analyses embedded as
> I've encountered a bit of a problem though in the processing of the
> resulting *.tex file that is as far as I can tell, down to the fact
> that my variable names have underscores ('_') in their names.
Can you replace the default row and/or column names with strings that
LaTeX will digest, such as c("AAA\\_ID", "OPN\\_1083AG", ...), since you
are using results=tex? You could automate it by something like:
> z <- c("AAA_ID", "OPN_1083AG") # really colnames(my_xtable)
> gsub("[_]", "\\\\_", z) # and assign back as colnames
 "AAA\\_ID" "OPN\\_1083AG"
after assigning the output of xtable to an object (untried).
> The relevant section of code is....
> ## Lists observations with missing data
> miss_1431 <- subset(gen, PPARG1.2_1431GA == "", select=
> xtable(miss_1431, caption="Missing data for PPARG1.2-1431GA")
> miss_p12a <- subset(gen, PPARG2_P12A_CG == "", select= c(AAA_ID,PPARG2_P12A_CG))
> xtable(miss_p12a, caption="Missing data for PPARG2-P12A_CG")
> and the variables in my data set have the following names...
> > names(gen)
>  "AAA_ID" "OPN_1083AG" "OPN_1239AC" "OPN_282TC"
>  "OPN_750CT" "OPN_443CT" "PPARG1.2_1431GA" "PPARG2_P12A_CG"
>  "OPG_1181GC"
> In tables that are generated have the character after the subscript
> subscripted, as opposed to being displayed as desired (see pg 4 of
> example output at
> http://slack.ser.man.ac.uk/files/genetic_analysis.pdf , please ignore
> the table on pg 3, as I said I'm just starting :-).
> After googling and searching R-help archives didn't reveal any obvious
> problems with this (other than in older versions of R underscores were
> not allowed in variable names).
> My question is, other than the obvious of renaming my variables, or
> manually editing the .tex file that Sweave produces, is there any way
> to have variable names with underscores correctly represented in the
> resulting tex file?
> The error log-file generated when running pdflatex on the .tex file
> can be viewed at http://slack.ser.man.ac.uk/files/genetic_analysis.log >
> Please let me know if I need to provide any more information, and my
> thanks in advance,
> > version
> platform i686-pc-linux-gnu
> arch i686
> os linux-gnu
> system i686, linux-gnu
> major 2
> minor 2.1
> year 2005
> month 12
> day 20
> svn rev 36812
> language R
> "Once, adv. - Enough
> Twice, adv. - Once too often"
> - Ambrose Bierce, The Devil's Dictionary
> Email - [hidden email] > Website - http://slack.ser.man.ac.uk/ > Blog - http://slack---line.blogspot.com/ > Flickr - http://www.flickr.com/photos/slackline/ >
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]
> I've encountered a bit of a problem though in the processing of
> the resulting *.tex file that is as far as I can tell, down to
> the fact that my variable names have underscores ('_') in their
Thanks to all who replied, I opted to go with Patrick Drechsler
solution of installing the underscore.sty package for the time being
but may well end up trying Roger Bivand's solution if at any stage I
wish to include subscripts in my main text (which I can envisage).
Thanks for the rapid and useful responses,
"Once, adv. - Enough
Twice, adv. - Once too often"
- Ambrose Bierce, The Devil's Dictionary