Giovanni Petris <gpetris at definetti.uark.edu> writes:
> Just a quick question:
>
> I tried
>
> > paste(sort(x),collapse="\; ")
> [1] "1; 1; 3; 4; 4; 7; 12; 19; 23"
> > paste(sort(x),collapse="\\; ")
> [1] "1\\; 1\\; 3\\; 4\\; 4\\; 7\\; 12\\; 19\\; 23"
>
> How can I get the following?
>
> [1] "1\; 1\; 3\; 4\; 4\; 7\; 12\; 19\; 23"
You can't. Notice that
> "1\; 1\; 3\; 4\; 4\; 7\; 12\; 19\; 23"
[1] "1; 1; 3; 4; 4; 7; 12; 19; 23"
The thing that gets printed is a representation of the character
string not the string itself. To be syntactically valid, backslashes
must be doubled in the representation, and the only other way you get
them is as prefix to characters that has to be escaped.
Of course, you could do
cat("[1] \"") ; cat(sort(x),sep="\\; ") ;
cat("\"\n")
or
cat("[1] \"", paste(sort(x), collapse="\\; "),
"\"\n")
;-)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._