[R] paste(" /" ") and paste(" /' ")

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 22 12:55:13 CEST 2009


Agustin Lobo wrote:
> I wish to write  "" using paste(), but
>   

paste() doesn't write anything, it constructs character vectors.  It is 
the auto-printing that is adding the backslashes.  Use cat() to write 
things without them:

 > cat(paste("\"","Hola","\"",sep=""))
"Hola"

In fact, cat() is flexible and you could just use

cat("\"","Hola","\"",sep="")

>
>  > paste("\"","Hola","\"",sep="")
> [1] "\"Hola\""
>  >
>
>
> while the same approach works with ''
>  > paste("\'","Hola","\'",sep="")
> [1] "'Hola'"
>
>
> why this difference? how could I do it to get "Hola" ?
>
>   
print() puts double quotes around strings when it prints them; that 
means it needs backslash escapes on double quotes within the string, but 
single quotes are fine.
Your vector did contain "Hola", but print() escaped the quotes.

Duncan Murdoch
> Thanks
>
> Agus
>
>




More information about the R-help mailing list