[R] gsub() issue...

David Winsemius dwinsemius at comcast.net
Tue May 17 12:54:03 CEST 2011


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 doesn’t work.
>
>
>
> Nevertheless, cat(original) works but print(original) doesn’t…
>
>
>
> Would you have an idea ?
>
>
>
> Thanks
>
>
>
> Thibault Charles
>
> Solamen
>
> Audencia - 8 route de la Jonelière
>
> 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



More information about the R-help mailing list