On 6/14/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Here is yet another solution. This is the simplest so far.
Lines.raw is as before and the output is a 3 column character
matrix.
section -
f - function(x) {
if (length(x) == 1) section - gsub([\\[\\]], , x)
if
Ah! I forgot to mention that it is possible to call awk from R:
a - system(awk -F'=' '/\\[/{a=$1;next}{print $1,$2,a}' example.ini,
intern=T)
z - textConnection(a)
read.table(z)
Christophe
On 6/14/07, Christophe Pallier [EMAIL PROTECTED] wrote:
On 6/14/07, Gabor Grothendieck [EMAIL
of the file being
processed.
--
View this message in context:
http://www.nabble.com/Read-Windows-like-.INI-files-into-R-data-structure--tf3908740.html#a11094865
Sent from the R help mailing list archive at Nabble.com.
__
R-help@stat.math.ethz.ch mailing list
var1=value1, A=value3 is almost pure R code.
Is it possible to use this feature to solve the problem?
Along the same lines: you may write a short script that converts the ini
file into R code that can be sourced.
From your example, you can generate the following R code:
Section1 - list()
)
It's sufficiently readable, but using something besides R is not sporty. ;)
--
View this message in context:
http://www.nabble.com/Read-Windows-like-.INI-files-into-R-data-structure--tf3908740.html#a11095800
Sent from the R help mailing list archive at Nabble.com
Vladimir Eremeev wrote:
Christophe Pallier wrote:
var1=value1, A=value3 is almost pure R code.
Is it possible to use this feature to solve the problem?
Along the same lines: you may write a short script that converts the ini
file into R code that can be sourced.
From your example, you
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]...
.Ini files are, for lack of a better description, ancient.
In this case a device is creating the INI files as part of an experiment, so
the file format cannot be changed (at least easily).
I've looked at XML files from time to time
R.
Neil
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Earl F. Glynn
Sent: Wednesday, June 13, 2007 2:57 PM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] Read Windows-like .INI files into R data structure?
[EMAIL PROTECTED] wrote in message
news:[EMAIL
Here is yet another solution. This is the simplest so far.
Lines.raw is as before and the output is a 3 column character
matrix.
section -
f - function(x) {
if (length(x) == 1) section - gsub([\\[\\]], , x)
if (length(x) = 1) return()
return(c(x, section))
}
# Lines -
I need to process some datasets where the configuration information was
stored in .INI-like files, i.e., text files with sections like this:
[Section1]
var1=value1
var2=value2
[Section2]
A=value3
B=value4
...
From Google and other searches I haven't found any package, or function
within a
nodes, parsing DOM.
Neil
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Earl F. Glynn
Sent: Tuesday, June 12, 2007 12:48 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Read Windows-like .INI files into R data structure?
I need to process some datasets where
Here is some code. It replaces [ and ] with = sign and reads the result
into a data frame, DF. DF2 is similar except the section is now in V3.
DF3 is like like DF2 except sections are carried forward and finally
we remove the rows which only had sections.
Lines.raw - [Section1]
var1=value1
In thinking about this a bit more here is an even shorter solution where
Lines.raw is as before:
# Lines - readLines(myfile.ini)
Lines - readLines(textConnection(Lines.raw))
Lines2 - chartr([], ==, Lines)
DF - read.table(textConnection(Lines2), as.is = TRUE, sep = =, fill = TRUE)
L - DF$V1 ==
Here is yet another simplification. This one uses na.locf from the zoo
package to shorten it further and also make it easier to understand.
Below we have one line to read in the .ini file, one line to transform the
characters [ and ] to = and =, the read.table line parses the result and
the next
14 matches
Mail list logo