[R] Searching for keyword values in a text (configuration) file

David Barron mothsailor at googlemail.com
Wed Sep 27 16:09:11 CEST 2006


Something like this?

> library(Hmisc)
> t <- readLines("clipboard")
> t
[1] "DEVICE = 'PC'"             "CPU_SPEED = '1999', '233'"

> ix <- grep("CPU_SPEED",t)
> loc <- substring.location(t[ix],",")
> cpu <- substring(t[ix],loc$first+2)
> cpu
[1] "'233'"


On 27/09/06, Andre Jung <ajung at gfz-potsdam.de> wrote:
> Hi,
>
> I would like to read values from an ASCII text file that contains
> information in the following format:
>
> DEVICE = 'PC'
> CPU_SPEED = '1999', '233'
> ...
>
> It's like a config file.
>
> How can I e.g. get R to read the 2nd value of CPU_SPEED?
> How do I go through text files and search for keywords and their values?
>
> Thanks a lot,
> Andre
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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 Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP



More information about the R-help mailing list