Re: [R] Search a string and modify it in a .txt file

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 21 May 2008 10:34:23 -0400

Instead of trying to modify the file, why not generate it from the data that you have. Is the array in your mail an example of one of many that have the configuration data? If so, why don't you just create the output file from that data. You can just loop through and do 'writeLines' to create the "init_file".

On Wed, May 21, 2008 at 7:05 AM, Romain <b.romain36_at_voila.fr> wrote:

> Hi there,
>
> I use R and I would like to be able to modify a file .txt "init_file" like
> this one :
>
> #
> ----------------------------------------------------------------------------
> #
> # Parameters A
> #
> ----------------------------------------------------------------------------
> #
> # Parameter 1
> PA1 = 15
>
> # Parameter 2
> PA2 = 3
>
> # Parameter 3
> PA3 = 2
>
> #
> ----------------------------------------------------------------------------
> #
>
>
> #
> ----------------------------------------------------------------------------
> #
> # Parameters B
> #
> ----------------------------------------------------------------------------
> #
>
> # Parameter 1
> PB1 = 6
>
> ...
>
> I have in a first time stocked the values I want to attribute to each
> parameter and so I would like to create several config files like the first
> one but with different values for each parameter. I have an array like this
> one
>
> PA1 PA2 PA3 PB1 ....
> j=1 12 2 1 5
> j=2 10 3 2 4
> j=3 11 4 3 6
> ...
>
>
>
> To create each file I use :
>
> for (j in 1:Nb_config_file)
> {
> file.copy("fichier_init",paste("Config_file",j,sep=""))
> }
>
> How can I do to search in each config file j created to modify the values
> of the parameters according to the j-th row of the array?
> I thought about looking for the lines "'Parameter' = Value" and modify this
> line in "'Parameter' = New_value" but I don't find any function to know the
> location of each string in my config_file...
>
> I could also use such a function to modify the format of the date to
> replace the ":" by something which can be used in a Directory/file name.
>
>
> Thanks you for your time and for your future help =)
>
>
> Cheers
>
> Romain
>
> ____________________________________________________
>
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[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.

Received on Wed 21 May 2008 - 14:47:53 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 Wed 21 May 2008 - 15:00:42 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