Re: [R] gsub() issue...

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 17 May 2011 06:54:03 -0400

The backslashes in the patt argument need to be doubled since "\" is a special regex character. Or it may work to set fixed =TRUE.

Either:
> original <- "INFILTRATION INF_BASE \\n AIRCHANGE=1"
> replace <- "INFILTRATION INF_BASE \n AIRCHANGE=3"
> new_texte <- gsub(patt=original,replace,text)

Or:
> original <- "INFILTRATION INF_BASE \n AIRCHANGE=1"
> replace <- "INFILTRATION INF_BASE \n AIRCHANGE=3"
> new_texte <- gsub(patt=original,replace,text, fixed=TRUE)

Both untested since the text example displays with smart-quotes and the R interpreter on a Mac refuses to accept. Incorrect quotes could be another theory about why it's not working.

-- 
David
On May 17, 2011, at 4:45 AM, Thibault Charles wrote:


> Hello R helpers,
>
>
>
> I get a problem using gsub() function.
>
>
>
> I have the following text :
>
>
>
> text <- INFILTRATION INF_BASE
>
> AIRCHANGE=1
>
>
>
> Then my code is :
>
>
>
> original <- "INFILTRATION INF_BASE \n AIRCHANGE=1"
>
>
>
> replace <- "INFILTRATION INF_BASE \n AIRCHANGE=3"
>
>
>
> new_texte <- gsub(original,replace,text)
>
>
>
> but it doesnt work.
>
>
>
> Nevertheless, cat(original) works but print(original) doesnt
>
>
>
> Would you have an idea ?
>
>
>
> Thanks
>
>
>
> Thibault Charles
>
> Solamen
>
> Audencia - 8 route de la Jonelire
>
> 44300 Nantes
>
> +33 2 40 37 46 76
>
>
>
>
> [[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.
David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ 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.
Received on Tue 17 May 2011 - 10:56:40 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 May 2011 - 11:40:08 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.

list of date sections of archive