Re: [R] regular expression

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 07 Apr 2007 - 22:53:06 GMT

On 4/7/07, Laurent Rhelp <laurentRhelp@free.fr> wrote:
> Gabor Grothendieck a écrit :
>
> >I assume is to replace single quotes in double quoted strings with single quoted
> >strings containing double quotes in place of the single quotes
> >
> that's rignt
>
> >while leaving
> >double quoted strings not containing single quotes as they are (i.e. leave them
> >as double quoted).
> >
> No, at the end, I have to replace all the double quotes (") by simple
> quote (')

In that case it simplifies to the following (same as before except for definition of f):

library(gsubfn)

squote <- "'" # single quote. This is a double quote, single quote, double quote dquote <- '"' # double quote This is a single quote, double quote, single quote

s <- "[\"...\" \"...'...\"]"
f <- function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('["][^"]*["]', f, s) # "['...' '...\"...']"



R-help@stat.math.ethz.ch 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. Received on Sun Apr 08 08:57:59 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 08 Apr 2007 - 09:31:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.