Sweave - problems with underscores in variable names...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sweave - problems with underscores in variable names...

nshephard
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.

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 - [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
Reply | Threaded
Open this post in threaded view
|

Re: Sweave - problems with underscores in variable names...

Roger Bivand
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 - [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
>

--
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: [hidden email]

______________________________________________
[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
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Sweave - problems with underscores in variable names...

Patrick Drechsler
In reply to this post by nshephard

Neil Shephard wrote on 16 Feb 2006 08:59:46 MET:

> 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.

<URL:http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underscore>

Adding "\usepackage{underscore}" to your preamble should help.


Patrick
--
Die Summe der Intelligenz auf dem Planeten ist eine Konstante.
Die Bevölkerung wächst.

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Sweave - problems with underscores in variable names...

nshephard
In reply to this post by nshephard
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,

Regards

Neil
--
"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