[R] Sweave - problems with underscores in variable names...
Roger Bivand
Roger.Bivand at nhh.no
Thu Feb 16 09:18:54 CET 2006
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
> required.
>
> 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
[1] "AAA\\_ID" "OPN\\_1083AG"
after assigning the output of xtable to an object (untried).
>
> The relevant section of code is....
>
> <<missing_data,echo=false,results=tex>>=
> ## Lists observations with missing data
> miss_1431 <- subset(gen, PPARG1.2_1431GA == "", select=
> c(AAA_ID,PPARG1.2_1431GA))
> 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)
> [1] "AAA_ID" "OPN_1083AG" "OPN_1239AC" "OPN_282TC"
> [5] "OPN_750CT" "OPN_443CT" "PPARG1.2_1431GA" "PPARG2_P12A_CG"
> [9] "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,
>
> Neil
>
> > version
> _
> platform i686-pc-linux-gnu
> arch i686
> os linux-gnu
> system i686, linux-gnu
> status
> 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 - nshephard at gmail.com
> Website - http://slack.ser.man.ac.uk/
> Blog - http://slack---line.blogspot.com/
> Flickr - http://www.flickr.com/photos/slackline/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Roger Bivand
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: Roger.Bivand at nhh.no
More information about the R-help
mailing list