I use pgfplotstable to read in external .csv data and print them in a formatted (MWE is unformatted) way.
The issue is, that the input .csv is not completely under my control. This means, it could be, that the input data are corrupted. A typically example would be, that the row length is unequal within these data.
So my question is, is there a way to test such a scenario?
MWE
\documentclass[10pt,oneside,a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\setlength\parindent{0pt}
% This example if fine
\begin{filecontents}{data1.csv}
A;B;C
D;E;F
G;H;I
\end{filecontents}
% This example is wrong
\begin{filecontents}{data2.csv}
A,B;C % => "," instead of a ";"
D;E;F
G;H;I
\end{filecontents}
\newcommand{\checkInutData}[1]{
% If input data is fine, do
\pgfplotstableread[col sep=semicolon]{#1}{\csvdata}
\pgfplotstableset{verb string type}
\pgfplotstabletypeset{\csvdata}
% Else
% Print, that input data are incorrect
}
\begin{document}
% This works!
\checkInutData{data1.csv}\\\\
% This should print an error
%\checkInutData{data2.csv}
\end{document}
awk: stackoverflow.com/questions/33050427/…. With a little bit of trouble you could also call such a oneliner from within your LaTeX code and proceed based on the return value, but it is easier to make sure the file is ok before you run LaTeX.\pgfplotstableto just get a return value if the import was successful or not. I think this could be helpful also for others.