PGFPlotsTable – How to Read Data from File and Create New Columns

pgfplotstable

I made this file parameters.dat:

parameter,    value
$K_1$,      0.00034
$K_2$,      0.0053
$K_3$,      0.07
$K_4$,      0.0027

Now I would like to generate a table in my .tex file with 4 columns: (1) Parameter; (2) Default value (the one from the .dat file); (3) Lower bound (0.75*value); (4) Upped bound (1.25*value). I tried with the following code but pdflatex gets stuck in an infinite loop:

\pgfplotstableset{
        create on use/lb/.style={
            create col/expr={\thisrow{value}*0.75}},
        create on use/ub/.style={
            create col/expr={\thisrow{value}*1.25}}
    }
    \pgfplotstabletypeset[
            col sep=comma,
        columns={parameter, value, lb, ub},
        columns/parameter/.style={
            column name={Parameter},
            string type
        }
        columns/value/.style={
            column name={Default Value}
        }
        columns/lb/.style={
            column name={Lower Bound}
        }
        columns/ub/.style={
            column name={Upper Bound}
        }
    ]
    {gfx/parameters.dat}

Best Answer

parameters.dat:

parameter,  value
K_1,        0.00034
K_2,        0.0053
K_3,        0.07
K_4,        0.0027

Code:

        \pgfplotstableset{
            create on use/lb/.style={
                create col/expr={\thisrow{value}*0.75}},
            create on use/ub/.style={
                create col/expr={\thisrow{value}*1.25}}
        }
        \pgfplotstabletypeset[
            col sep=comma,
            columns={parameter, value, lb, ub},
            columns/parameter/.style={
                column name={Parameter},
                string type,
                preproc cell content/.append style={/pgfplots/table/@cell content/.add={$}{$}}
            },
            columns/value/.style={
                column name={Default Value}
            },
            columns/lb/.style={
                column name={Lower Bound}
            },
            columns/ub/.style={
                column name={Upper Bound}
            }
        ]{parameters.dat}
Related Question