Here is an example of how to create the init files:

x <- read.table(textConnection("             PA1      PA2       PA3     PB1
j=1           12        2         1        5
j=2           10        3         2        4
j=3           11        4         3        6"), header=TRUE)
closeAllConnections()
for (i in 1:nrow(x)){
    outfile <- file(paste("init.", i, ".txt", sep=''), "w")
    for (j in colnames(x)){
        writeLines(paste(j, '=', x[i,j], sep=''), outfile)
    }
    close(outfile)
}
This will create a file that will look like this:

> readLines('init.1.txt')
[1] "PA1=12" "PA2=2"  "PA3=1"  "PB1=5"
>


On Wed, May 21, 2008 at 7:05 AM, Romain <b.romain36@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@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]]

