On 13-09-02 3:18 PM, David Epstein wrote:
Dear Thierry,

Your suggestion doesn't work on my version of R. Here's what I get
gsub("_", "\_", print(version$platform)
Error: '\_' is an unrecognized escape in character string starting ""\_"
print(gsub("_", "\_", version$platform))
Error: '\_' is an unrecognized escape in character string starting ""\_"

sub("_", "\\_", version$platform)
[1] "x86_64-apple-darwin10.8.0"
Sweave does not evaluate this expression when \Sexpr is applied and a tex error 
results

sub("_", "\\\_", version$platform)
Error: '\_' is an unrecognized escape in character string starting ""\\\_"
Error message from R

sub("_", "\\\\_", version$platform)
[1] "x86\\_64-apple-darwin10.8.0"
R evaluates this. However, the above examples indicate a deficiency/possible 
bug in the command sub, because sub does not seem to be able to output an 
expression with a single backslash.

The final result has a single backslash. The print() function doubles it so you can tell it from an escape of the next letter. If you use cat() instead of the implicit print() you'll see the text that is there.

I tried the previous version as follows in my .Rnw document
\Sexpr{print(sub("_", "\\\\_", version$platform))}
When Sweave is run, this expression is evaluated to illegal LaTeX


You need to give more details, e.g. what actually appeared in the .tex file and in what context, if you want help with this.

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to