Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can R paste() output "\"?

Tags:

text

r

As stated in the Intro to R manual,

paste("\\")

prints

[1] "\\"

Is it possible for paste to print out

[1] "\"

?

update: I didn't want Gavin's this nice answer to get stuck in the comments below, so I'll paste it here:

print(xtable(as.matrix("\\citep{citation}")), sanitize.text.function = function(x) {x}) 
like image 840
David LeBauer Avatar asked Dec 16 '22 19:12

David LeBauer


1 Answers

You are confusing how something is stored and how it "prints".

You can use paste to combine a \ with something else, but if you print it then the printed representation will have \ to escape the \, but if you output it to a file or the screen using cat instead, then you get the single \, for example:

> tmp <- paste( "\\", "cite{", sep="" )
> print(tmp)
[1] "\\cite{"
> cat(tmp, "\n")
\cite{ 
like image 177
Greg Snow Avatar answered Jan 21 '23 18:01

Greg Snow