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

2006-09-27 Thread Andre Jung
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

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

2006-09-27 Thread Andre Jung
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

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

2006-09-27 Thread Gabor Grothendieck
Read in data using readLines and replace = with comma and delete all spaces. Then reread using read.table and set the rownames to column 1 removing column 1. # test data Lines0 - DEVICE = 'PC' CPU_SPEED = '1999', '233' # if reading from a file then # replace next line with something like Lines

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

2006-09-27 Thread David Barron
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 [EMAIL PROTECTED] wrote: Hi, I

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

2006-09-27 Thread Gabor Grothendieck
Here is one more solution using the same Lines0 from last time. This one uses strapply from gsubfn to pick out all the fields in each line creating a list named by the keywords (rather than a data frame as in the previous solution). The names of the components are the keywords so we remove them

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

2006-09-27 Thread Gabor Grothendieck
Here is a slight simplification of this one using row.names= in the read.table to avoid the subsequent manipulations. We use Lines0 defined in the earlier post: # replace next line with something like Lines - readLines(myfile.dat) Lines - readLines(textConnection(Lines0)) Lines - gsub(=, ,,