[R] how to insert a double quote with the paste function?

David Khabie-Zeitoune dave at evocapital.com
Thu Sep 11 10:15:07 CEST 2003


You seem to have the right answer already, unless I misunderstand...

If I define:

> x = "Hello \"World\""
Then the default print method for this character string will give the rather ugly looking:

> x
[1] "Hello \"World\""

But this is just R telling us that it does recognise the escape sequence \". If we pass this variable to a more output-friendly function like cat, we get:

> cat(x)
Hello "World"

So the variable x really does contain  'Hello "World"', it's just that R's default print method will show the escape characters used in a string. 

-----Original Message-----
From: Philippe Hupé [mailto:Philippe.Hupe at curie.fr] 
Sent: 11 September 2003 08:55
To: 'r-help at stat.math.ethz.ch'
Subject: [R] how to insert a double quote with the paste function?


I would like to write in a variable the following string :

Hello "World"

If I do cat("Hello ","\"World\""), I have the good result on the screen 
but it can not be affected to a variable. If I do the same thing with 
paste paste("Hello ","\"World\"") it does not work since \" seems to be 
not recognized. So what is the trick to do that.




Philippe Hupé
Institut Curie - Equipe Bioinformatique
26, rue d'Ulm - 75005 PARIS France
+33 (0)1 44 32 42 75

Philippe.Hupe at curie.fr <mailto:Philippe.Hupe at curie.fr>

R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

More information about the R-help mailing list