[R] Parsing configuration files

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon May 18 14:19:40 CEST 2009


Uwe Ligges wrote:
>
>
> Marie Sivertsen wrote:
>> Dear list,
>>
>> Is there any functionality in R that would allow me to parse config
>> files?
>
> Which kind of config files? R has read.dcf, for example.
>

indeed, there are quite a number of more or less unambiguously specified
configuration file formats.

for the lack of an existing solution (or, more likely, due to my
ignorance) i've crufted together a trivial script that parses simple
ini-like config files, with square-bracketed section headers, like this:

    [foo]
    bar = BAR
   
    [bar]
    foo = ...

you just source the script, specify the config file, and get a nested
list of config parameters, e.g.

    source('http://miscell.googlecode.com/svn/rconfig/rconfig.r')
    config = rconfig('somefile.cfg')
    config$foo$bar
    # "BAR"

the functionality is rudimentary and not fool-proof, no string-to-number
parsing, no comment skipping, etc.  i'm not really suggesting it as a
solution to your (underspecified) problem, feel free to modify/extend it
to match your needs.

vQ




More information about the R-help mailing list