Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
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.. –  Tahnoon Pasha Nov 1 '12 at 14:26
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
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. –  Tahnoon Pasha Nov 1 '12 at 14:44
    
Ah, of course. makes sense. –  Christian Feuersänger Nov 1 '12 at 16:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.