Skip to content

how to manually enter an double quote as data feed?

3 messages · bonnieyuan, Justin Haynes, Nordlund, Dan (DSHS/RDA)

#
I'm doing a text mining project where I have to manually enter a double quote
as an element inside a vector.

I tried

char[10]='"'#where i enclosed the double quote in a pair of single quotes.

But the result is [1] "\"". Somehow a back slash is added automatically.

I also tried to enclose the double quote in a pair of double quotes. That
didn't work either.

I'm using Mac and latest release of R.

Thank you!

Bonnie Yuan


--
View this message in context: http://r.789695.n4.nabble.com/how-to-manually-enter-an-double-quote-as-data-feed-tp4192283p4192283.html
Sent from the R help mailing list archive at Nabble.com.
#
Bonnie,

The backslach character in not actually there.  Since the double quote character has special meaning in R, it needs to be 'escaped' to change its special meaning to become a literal double quote character.  That is the function of the \ escape character.

Try the following

s1 <- '"'  #assign as you did 
s2 <- "\"" #assign using escape character

s1         #displays with backslash
nchar(s1)  #but there is only 1 character in the string
s2
nchar(s2)

print(s1)  #prints backslash indicating literal double quote
cat(s1,'\n') #cat function displays without the backslash
             #notice n character is escaped, creating a newline character


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204