# Problems with pgfplots, loops inside tikzpicture and reading from files [closed]

I was trying to implement this method (How to import ASCII coordinates to TikZ) to import coordinates and draw them, but I am having this problem

Undefined control sequence \end{tikzpicture}
Extra }, or forgotten \endgroup \end{tikzpicture}
Extra \endgroup \end{tikzpicture}
Extra \endgroup \end{tikzpicture}
Too many }'s \end{tikzpicture}
Extra \endgroup \end{tikzpicture}
\begin{document} ended by \end{tikzpicture}. \end{tikzpicture}
Extra \endgroup \end{tikzpicture}
Too many }'s \end{tikzpicture}
Extra \fi \end{tikzpicture}


My code is simply

\documentclass{book}
\usepackage{tikz}
%Defining loops for tikz
\def\myloop#1#2#3\repeat{\def\filenm{#2}\def\body{#1#2#3}\iterate}

\def\iterate{\body\ifeof\filenm\let\next\relax\else\let\next\iterate\fi\next}

\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows, calc}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=tikz/]
\pgfplotsset{compat=1.9}

\begin{document}

\openin\bar=borrar.tex

\begin{tikzpicture}
\end{tikzpicture}
\end{document}


It works whenever I do not include the package pgfplots, but I need this package for some plots. Is there any other way to make it work? Thanks in advance.

Edit:

sorry I forgot to include this. File borrar.tex is just the coordinates for two lines

(0.000000,0.000000) -- (0.000000,2.000000)
(0.000000,0.000000) -- (2.000000,2.000000)


Error in the logfile

\bar=\read2
! Undefined control sequence.
\endtikzpicture ...r@layerlist@globally \endscope
\let \pgf@baseline =\pgf@s...
l.17 \end{tikzpicture}


## closed as off-topic by Stefan Pinnow, Zarko, Mensch, Stefan Kottwitz♦Nov 10 '16 at 22:14

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to TeX.SX! Instead of the shortened error messages, please report what's in the log file, which is usually more informative. For instance the first error message is about \endscope. Another thing: we don't have borrar.tex and can't guess its contents. – egreg Nov 23 '13 at 22:03
• Thanks for your comment! Should I include the entire log file? It is pretty long. – balborian Nov 23 '13 at 22:14
• No, that should be sufficient. – egreg Nov 23 '13 at 22:15
• If you want to read the coordinates line by line from the file you need to use \readline instead of \read. – Martin Scharrer Nov 24 '13 at 10:31
• I'm voting to close this question as off-topic because with PGFPlots v1.14 the given example compiles without any error message (when not using the external library, which wasn't explicitly mentioned in the question). – Stefan Pinnow Nov 10 '16 at 21:31