I have many tab separated csv files which I would like to convert into tables automatically in tabular environment of latex. Tables are named: log_% where % can be one of the symbols \in {at,be,fr,....}. For example each file looks like below:
accuracy timepred timelearn timelearn2 timelearn4 rmsetrain
0.987747 0.532 2.44 nan nan 0.987676
0.987747 0.528 2.396 nan nan 0.987676
0.987747 0.544 2.408 nan nan 0.987676
0.987747 0.496 2.388 nan nan 0.987676
0.987747 0.436 2.432 nan nan 0.987676
0.987747 0.428 2.444 nan nan 0.987676
0.987747 0.464 2.452 nan nan 0.987676
0.987747 0.428 2.452 nan nan 0.987676
0.987747 0.464 2.46 nan nan 0.987676
0.987747 0.484 2.448 nan nan 0.987676
I tried the below code which unfortunately does not work!
\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{csvsimple}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{array}
\usepackage{pgfplotstable}
\newcounter{listtotal}\newcounter{listcntr}%
\NewDocumentCommand{\names}{o}{%
\setcounter{listtotal}{0}\setcounter{listcntr}{-1}%
\renewcommand*{\do}[1]{\stepcounter{listtotal}}%
\expandafter\docsvlist\expandafter{\namesarray}%
\IfNoValueTF{#1}
{\namesarray}% \names
{% \names[]
\renewcommand*{\do}[1]{\stepcounter{listcntr}\ifnum\value{listcntr}=#1\relax##1\fi}%
\expandafter\docsvlist\expandafter{\namesarray}}%
}
\begin{document}
\newcommand{\namesarray}{at,br,cz,dk,fi,ie,nb,no,pt,se,be,ch,de,es,fr,it,nl,pl,ru,uk}%
\foreach \i in {0,...,20}{
\newcommand{\name}{\names[\i]}
\name
\csvautotabular[separator=tab]{logs/log_\names[\i]} \par
}
\end{document}
By executing above code I get an error:
! Package csvsimple Error: File 'logs/log_\names [0]' not existent, not readable, or empty!.
The same example works by hard coding the symbol as follows:
\csvautotabular[separator=tab]{logs/log_at} \par
in place of
\csvautotabular[separator=tab]{logs/log_\names[\i]} \par
I uploaded the working solution by hardcoding on the following link: goo.gl/nbI5TQ
I believe the problem is that macro \i gets expanded and tabular environment fails to expand \names. But I am not sure. Is it possible to expand the macro \names[\i] as a group and not just \i?
I would appreciate any kind of minimal help to solve my problem.
Thanks :)
pgffor
?pgfplotstable
. I will edit.