[R] How to get '\h' through print() or paste()?
Kurt Hornik
Kurt.Hornik at ci.tuwien.ac.at
Sun Mar 21 13:08:34 CET 1999
>>>>> Knut Suebert writes:
> Hello,
> [really hoping not to ask something the 1001th time]
> I need single backslashes printed for generating TeX-code.
> That works:
>> print("\begin{tabular}")
> [1] "\begin{tabular}"
> But \h seems to be interprated in some way:
>> print('\hline')
> [1] "hline"
> Hm, trying to mask the backslash:
>> print('\\hline')
> [1] "\\hline"
> But I need "\hline"...
> Is there a way without generating strange code in a temporary file for
> "sed"ing it? It would be also nice to get rid of the leading number in
> brackets for each line of output...
Escaping the backslash with another one is the right thing and gives you
what you want, it is just that print() returns it the way it was typed
in.
Consider
R> x <- "\\"
R> nchar(x)
[1] 1
R> print(x)
[1] "\\"
R> cat(x, "\n")
\
R> substr(x, 1, 1)
[1] "\\"
R> substr(x, 2, 2)
[1] ""
-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list