1

I'm trying to encapsulate some pgfplotstable code that involves setting up a row predicate. If you are checking table values amongst the predicate code you need access to the table and the only thing that seems to work here is hardwiring the command name of the loaded table, which does not lend itself to code reuse, and there are also other aspects of the style that change on a case by case basis. But, if you put this stuff inside a macro, there ends up being confusion about whose #1 is whose, given that writing the code for a row predicate involves distinguishing between the immediate parameter #1 for the style and the delayed parameter '##1' for the row number when the code is actually used.

1
  • Wow, nobody liked this question. Is it such a bad idea? Nov 25, 2014 at 22:19

1 Answer 1

1

The following example call, \mysetpredicate, shows that you have to double up on the hashes. Four, for what will become two in the predicate itself to get the row number. Two, for what will become one to get the style parameter and one for the parameter to the wrapping function. I was surprised that I could just pass the file link in as is. I originally assumed I couldn't and wasted a lot of time trying all kinds of tricky stuff that didn't work. First build your table with either pgfplotsreadtablenew or pgfplotsreadtableread then call \mysetpredicate{\mytable} before calling \pgfplotstabletypeset.

\def\mysetpredicate#1{
    \pgfkeys{%
        /pgfplots/table/select rows/.style={%
            row predicate/.code={%
            \ifnum####1=0\relax\myrowtally=1\relax\mynumrows=##1\relax\fi
            \ifnum\myrowtally>\pt@numrows@val\pgfplotstableuserowfalse
            \else\pgfplotstablegetelem{####1}{mycheckcolumn}\of{#1}%
                \ifnum\pgfplotsretval>1
                    \pgfplotstableuserowfalse
                \else\advance\myrowtally by 1
            \fi\fi
            }
        }
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .