Hi, How can I get double quotes embedded in the string? Example: -------------- str1 <- '"xyz"' ## desired output # abc"xyz" qr2 <- paste('abc',str1,sep='') print(qr2) ----------------- Actual output:> [1] "abc\"str\""I also tried putting an escape sequence before the quote, but couldn't get the string that I want. thanks, [[alternative HTML version deleted]]
Paul - When you print a string, it escapes the quotes with a backslash. That's a property of the print() function, not the string itself. If you want to see the string, use cat(). The nchar() function is also useful:> str1 <- '"xyz"' > qr2 <- paste('abc',str1,sep='') > print(qr2)[1] "abc\"xyz\""> cat(qr2,'\n')abc"xyz"> nchar(qr2)[1] 8 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spector at stat.berkeley.edu On Wed, 30 Jun 2010, Paul Evans wrote:> Hi, > > How can I get double quotes embedded in the string? > > Example: > > -------------- > str1 <- '"xyz"' > > ## desired output > # abc"xyz" > > qr2 <- paste('abc',str1,sep='') > print(qr2) > > ----------------- > > Actual output: > >> [1] "abc\"str\"" > > I also tried putting an escape sequence before the quote, but couldn't get the > string that I want. > > > thanks, > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
You can try noquote also: noquote(paste('abc', '"xyz"', sep = "")) On Wed, Jun 30, 2010 at 3:31 PM, Paul Evans <p.evans48@yahoo.com> wrote:> Hi, > > How can I get double quotes embedded in the string? > > Example: > > -------------- > str1 <- '"xyz"' > > ## desired output > # abc"xyz" > > qr2 <- paste('abc',str1,sep='') > print(qr2) > > ----------------- > > Actual output: > > > [1] "abc\"str\"" > > I also tried putting an escape sequence before the quote, but couldn't get > the > string that I want. > > > thanks, > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]