[R] Sweave: printing an underscore in the output from an R command

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Mon Sep 2 17:47:29 CEST 2013


You have to escape the underscore

\Sexpr{gsub("_", "\_", print(version$platform))}

Best regards,

Thierry

________________________________________
Van: r-help-bounces op r-project.org [r-help-bounces op r-project.org] namens David Epstein [David.Epstein op warwick.ac.uk]
Verzonden: maandag 2 september 2013 17:38
Aan: r-help op r-project.org
Onderwerp: [R] Sweave: printing an underscore in the output from an R command

I am working with Sweave and would like to print out into my latex document the result of the R command
version$platform
So what I first tried in my .Rnw document was \Sexpr{print(version$platform)}.

However, the output from this command is the string "x86_64-apple-darwin10.8.0" (without the quotes). This contains an underscore, which is a special character in tex and so I get an error message from latex.

I can get round this by using sub to replace underscore with a space, but I would like to know how to print the underscore if I really wanted to do so.

______________________________________________
R-help op r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.



More information about the R-help mailing list