I have found a bug while writing a table to a file with \pgfplotstablesave
.
In dependance of the col sep
key, some times there is written an additional column to the file. Or more specific the col sep
symbol is wrongly placed at the of the line.
To show this bug I have written the following file.
The simple benchmark of writing the table to a file and reread it shows the bug.
\documentclass[parskip=half]{scrartcl} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{pgfplotstable} \pgfplotsset{compat=1.15} \usepackage{filecontents} \begin{filecontents}{table.csv} A B 1 2 \end{filecontents} \newcommand{\checktable}[1]{ Test for \texttt{#1}\par % write to file \pgfplotstablesave[ col sep = #1, ]{\data}{tableTemp_#1.csv} % read again \pgfplotstableread[ col sep = #1,] {tableTemp_#1.csv}\datatemp % show info \pgfplotstableforeachcolumn\datatemp\as\col{% column name is ‘\col’; index is \pgfplotstablecol; \\ } } \begin{document} \pgfplotstableset{row sep = newline} % read original table \pgfplotstableread[ col sep = space, ]{table.csv}\data Read directly from \texttt{table.csv} \par % show info \pgfplotstableforeachcolumn\data\as\col{% column name is ‘\col’; index is \pgfplotstablecol; \\ } \checktable{space} \checktable{tab} \checktable{semicolon} \checktable{comma} \checktable{colon} \checktable{braces} \checktable{ampersand} \end{document}
And the output
Read directly from table.csv
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
Test for space
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
Test for tab
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
Test for semicolon
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
column name is ‘2’; index is 2;
Test for comma
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
column name is ‘2’; index is 2;
Test for colon
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
column name is ‘2’; index is 2;
Test for braces
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
Test for ampersand
column name is ‘A’; index is 0;
column name is ‘B’; index is 1;
column name is ‘2’; index is 2;
See
pgfplotstable.code.tex
line 1039-1073. It does not test whether a cell is in the last column and append a comma (or colon/or semicolon/or ampersand).You might want to do something like
Playing code
Related
Bugs:
#1