[R] Search&replace string?

From: Romain <b.romain36_at_voila.fr>
Date: Wed, 28 May 2008 17:13:58 +0200 (CEST)

Hi there,

I would like to know if it is possible to modify a text file with a R function. In fact I would like to know if a function "Search & Replace" exists.

My problem is to create config files from a Base file in which I have to modify values of parameters.

My Base File:


Param1= V1_1


Param2 = V2_1
Param3 = V3_1

What I would like for each created file i:


Param1= V1_i


Param2 = V2_i
Param3 = V3_i

For the moment my solution is to read each line of the config file, modify if needed the line and recopy it in the new file. But the problem is that my file is about 500 lines and I would like to create a lot of different version of Config_file from my Base file so with this method it takes a long time and i'm sure i can improve it. (For example for 85 differents files I have to wait 10min...)

My dream would be a function like this one : Function <- function(Base_file, Param_array, Value_array) {

    file.copy(Base_file, Config_file)
    for (i in length(Param_array)

         Search&Replace(Config_file, "Param_array[i] = something", "Param_array[i] = Vallue_array[i]")     }

I hope I have been clear enough. If not, don't hesitate to ask me more details!

Thank you for your help.
Have a good day!

Vous aussi bénéficiez d'1 Go de stockage gratuit en ligne avec Voila http://macle.voila.fr

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 Wed 28 May 2008 - 17:17:59 GMT

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 Thu 29 May 2008 - 17:30:45 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