Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20110517/1812d6c6/attachment.pl>
Hello Thibault Charles,> I have the following text : > text <- ?? INFILTRATION INF_BASE > > AIRCHANGE=1 ??becomes: text <- "INFILTRATION INF_BASE\nAIRCHANGE=1"> original <- "INFILTRATION INF_BASE \n AIRCHANGE=1"There are spaces around "\n". That's why text != original Try original <- "INFILTRATION INF_BASE *\n *AIRCHANGE=1" Bye, Sebastian
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
Hi Charles, It's not clear to me what you mean by "doesn't work".> test <- "Interesting 1\nPoint\n" > cat(test)Interesting 1 Point> test1 <- gsub("ing 1\nP","ing 3\nP", test) > cat(test1)Interesting 3 Point>Cheers Andrew On Tue, May 17, 2011 at 10:45:31AM +0200, 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.-- Andrew Robinson Program Manager, ACERA Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ Forest Analytics with R (Springer, 2011) http://www.ms.unimelb.edu.au/FAwR/ Introduction to Scientific Programming and Simulation using R (CRC, 2009): http://www.ms.unimelb.edu.au/spuRs/