Re: [R] Read Windows-like .INI files into R data structure?

From: Vladimir Eremeev <wl2776_at_gmail.com>
Date: Wed, 13 Jun 2007 02:22:15 -0700 (PDT)

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 can generate  the  following R code:

>
> Section1 <- list()
> Section1['var1'] <- value1
> Section1['var2'] <- value2
> Section2 <- list()
> Section2['A'] <- value3
> Section2['B'] <- value4
>
>
> with the following awk script (using awk -F'=' -f conv.awk example.ini >
> example.R)
>
> ### conv.awk
> $1 ~ /\[/ { gsub(/[\[\]]/,""); # remove the brackets
> listname = $1;
> print $1 " <- list()";
> next }
> { print listname "['" $1 "'] <- " $2 }
>

> (I know, it looks cryptic... so I am shooting myself in the foot after
> claiming that awk scripts are typically quite readable ;-)
>
> Christophe Pallier (http://www.pallier.org)
>

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.

______________________________________________
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.
Received on Wed 13 Jun 2007 - 09:57:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 13 Jun 2007 - 10:31:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.