bib <- "\\c...">

Print backslash in R lines

GNU R 3.02

> bib <- "\cite"
Error: '\c' is an unrecognized escape in character string starting ""\c"
> bib <- "\\cite"
> print(bib)
[1] "\\cite"
> sprintf(bib)
[1] "\\cite"
> 

how can i print a bib string variable with just one "\"?

(I tried everything imaginable and found that R treats "\\" as one character.)

I see that in many cases this is not a problem, since it is usually processed inside R, say, if the line should be used as text for the graph.

But I need to send it to LaTeX. So I really need to remove it.

I see what the cattrick is doing. If a cat could be made only to send its result to a string.

+4
source share
3 answers

You must use cat.

bib <- "\\cite"
cat(bib)
# \cite

## [1], knitr. :

<<newChunk,echo=FALSE,comment=NA,background=NA>>=
bib <- "\\cite"
cat(bib)
@

\cite. , .

+4

"\ cite" . , "\ c" cntrl-c. , . . ?Quotes. 4 -. , :

nchar("\\cite")
[1] 5
+4

OK

<<echo=FALSE,result='asis'>>
result <- cat(rbib)
@

( result <-, [1]). .

+2

All Articles