I'm attempting to create a pgfplots group plot in which each curve is made from a pre-loaded pgfplots table in an automated way. The intended application is for a complicated drawing involving many tables. The MWE below illustrates the issue. With suitable use of \expandafter (thanks to the answer to this previous question: Refer to a loaded pgfplotstable via csname), I can get a loop over multiple tables to work with \pgfplotstabletypeset. A similar loop which tries to plot both datasets fails to compile. I'd like to be able to use the unaltered \addplot syntax in such a loop. There may be a way of wrapping the invocation of \addplot in a \newcommand which could get the \expandafter trick to work, but defining a new macro for every plot I'd like to make will be inconvenient and potentially fragile. Ideally, I'd like to be able to (1) use the name passed to \pgfplotsinvokeforeach to call \addplot multiple times with different options, and (2) if possible, switch to using a numerical list, e.g., \pgfplotsinvokeforeach{0,...,5}, to implement the plotting loop.
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread{
a b
1 4
2 5
3 6
}{\testTableOne}
\pgfplotstableread{
a b
1 2
2 3
3 4
}{\testTableTwo}
\pgfplotsinvokeforeach{One,Two}{%
\expandafter\pgfplotstabletypeset\expandafter{\csname testTable#1\endcsname}
}
\begin{tikzpicture}
\begin{groupplot}[group style = {group size = 1 by 2}]
\pgfplotsinvokeforeach{One,Two}{
\nextgroupplot
\addplot table[ x = a, y = b ]
% This fails to compile
{\csname testTable#1\endcsname};
% This works, but doesn't vary the plot
%{\testTableOne};
}
\end{groupplot}
\end{tikzpicture}
\end{document}

\addplotnamed[sharp plot, mark=*, mark options={fill=green}] table[ x = a, y = b ] {testTable#1};currently fails to compile. – Steven Gardiner Jul 04 '21 at 15:38[...]part aftertable? – egreg Jul 04 '21 at 16:13tablecan take they exproption which needs braces for calling\thisrow{}, etc. – Steven Gardiner Jul 04 '21 at 16:17tablesyntax, but… – egreg Jul 04 '21 at 19:37