Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

Re: [R] regular expression

Laurent Rhelp

2007-04-08

Replies:

Gabor Grothendieck a écrit :

>On 4/7/07, Laurent Rhelp <laurentRhelp@(protected):
>
>
>>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@(protected)
>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.
>
>
>
>
I have the following error message :

> gsubfn('["][^"]*["]', f, s) #  "['...' '...\"...']"
Erreur dans parse(file, n, text, prompt) : erreur de syntaxe dans
"c("[\",replacement(""...\"""

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.