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.
Justin Haynes
2011-Dec-13 23:27 UTC
[R] how to manually enter an double quote as data feed?
"\"" is how its displayed on the screen. however, if you write your object to a csv it will be correct. r cant display """ as it is so it is escaping the second double quote for you however, "'" (double quote single quote double quote) does display correctly as well as save correctly. If that doesn't answer your question, some more back story on what you're trying to do would help. Justin On Tue, Dec 13, 2011 at 2:03 PM, bonnieyuan <bby2103@columbia.edu> wrote:> 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. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Nordlund, Dan (DSHS/RDA)
2011-Dec-13 23:58 UTC
[R] how to manually enter an double quote as data feed?
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of bonnieyuan > Sent: Tuesday, December 13, 2011 2:04 PM > To: r-help at r-project.org > Subject: [R] how to manually enter an double quote as data feed? > > 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 >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