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

Vladimir Eremeev wl2776 at gmail.com
Wed Jun 13 11:22:15 CEST 2007



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.



More information about the R-help mailing list