2

I'm trying to get a table from R into a pgfplotstable to edit for printing.

the r code is

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
    \pgfplotstableread[format=inline,row sep=\\,col sep=&,header=false,
    ignore.chars={\ }]{%
     <<echo=FALSE,results='asis'>>=
     temp=rbind(c(rep("",6)),c("",seq(2012,2016,1)),c(rep("",6)))
     print(xtable(temp),include.rownames=F,include.colnames=F,only.content=T,hline.after=NULL)
     @
    }\mytable
\end{document}

and the output has the space at the end shown below and fails to compile with an error. The extra space at the end seems to be an xtable problem rather than a knitr one, but I'm not sure this one is right to ask on SO, and am hoping perhaps there is another way to get the info into the pgfplotstableread that I haven't thought of.

\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
    \pgfplotstableread[format=inline,row sep=\\,col sep=&,header=false,
    ignore.chars={\ }]{%
    % latex table generated in R 2.15.1 by xtable 1.7-0 package
    % Thu Nov  1 19:19:18 2012
      &  &  &  &  &  \\ 
       & 2012 & 2013 & 2014 & 2015 & 2016 \\ 
       &  &  &  &  &  \\   

    }\mytable
\end{document}

Thanks

1
  • Adding a shamefaced half solution. write.table(temp,sep='&',eol='\\\\',quote=F,row.names=F,col.names=F) ... but that doesnt really give me access to all the text sanitization benefits of xtable.. Commented Nov 1, 2012 at 14:26

1 Answer 1

4

You can try to tell pgfplotstable that it should filter out newline characters from the input table. That should not pose any difficulty because you do not need them in your case.

To this end, you can simply use ignore chars={\ ,\^^M} . Why do you need \, by the way? The \^^M is a TeX-shorthand which means (and protects) end-of-line.

2
  • Hi @ChristianFeuersanger. I was on the wrong track again. I saw the new line as a large sequence of spaces and was trying to get pgfplotstable to ignore them. Thanks for your help. Commented Nov 1, 2012 at 14:44
  • Ah, of course. makes sense. Commented Nov 1, 2012 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .