[R] Alter a line in a file.
Petr PIKAL
petr.pikal at precheza.cz
Thu May 5 15:39:33 CEST 2011
Hi
r-help-bounces at r-project.org napsal dne 05.05.2011 15:13:34:
> Joel <joda2457 at student.uu.se>
> Odeslal: r-help-bounces at r-project.org
>
> 05.05.2011 15:13
>
>
> jholtman wrote:
> >
> > a <- readLines(textConnection('setting1="value1"
> > setting2="value2"
> > setting3="value3"
> > setting4="value4"'))
> > closeAllConnections()
> > # change values
> > ac <- sub('setting4="value4"', 'setting4="value5"', a)
> > writeLines(ac, con='myFile.txt')
> >
>
> Problem is that I dont know the value on all the settings that I wanna
> change otherwise that looks like something to continue on.
>
But in that case how would you like to select the setting?
>
>
> Petr Pikal wrote:
> >
> > What file, what is its structure, is it some R object or separate
file?
> > What did you try and what went wrong?
> >
> > Regards
> > Petr
> >
>
> Just a normal textfile nothing fancy
> Ive tried diffrent kind of ways of useing my OS witch is linux by the
system
> command to do it for me but Im not good enought on regexp to get it to
work
> properly.
I read the simple text file by read.table
> data
V1
1 setting1="value1"
2 setting2="value2"
3 setting3="value3"
4 setting4="value4"
> grep("4", data$V1)
[1] 4
Regards
Petr
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Alter-a-line-
> in-a-file-tp3498187p3498316.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list