TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an R script that generates a data frame, that I export to a CSV file. The data looks something like this:


I have an ongoing org-mode document in which I'd like to report this data. I'd like to add a table that looks something like this:

| Variant | X Axis | Y Axis | N | Mean | Standard Deviation | Standard Error |

The data will change frequently over the coming months. I'd like org-mode to auto-magically read a CSV file, to construct my org-table on-the-fly. I'd hoping to avoid copying and pasting results each time.

Is there some org-mode or emacs+ESS magic I can use to populate my empty table, with source data from my CSV file?

share|improve this question
This has nothing to do with TeX, however, the org-mode mailing list is highly active and I suggest you direct your question there. – zeroth Jul 16 '13 at 15:12

I put the logic right in the document, but you can encode it inside a macro, I'm pretty sure. Note that y-axis column is blank because your R-script didn't include it. Also, this logic reads space-separated, not comma-separated input file (I made sure that your data did not have spaces in the data). I had placed that input in the file Rscript.txt.

Herbert's answer at How to programmatically make tabular rows using `\whiledo` ? was indispensible to my solution.

  % Based on:
  % http://tex.stackexchange.com/questions/7590/
  % how-to-programmatically-make-tabular-rows-using-whiledo
\addtabtoks{ Variant & X Axis & Y Axis & N & Mean & Standard Deviation &
Standard Error \\\hline}
\whiledo{\value{index} < \nrows}{%
    \arrayij{first}{\thetabindex}{2} &
    \arrayij{first}{\thetabindex}{3} &
    \arrayij{first}{\thetabindex}{4} &
    \arrayij{first}{\thetabindex}{5} &
    \arrayij{first}{\thetabindex}{6} &

enter image description here

share|improve this answer

You can use the xtable library of R and insert manually in the LaTeX document, or better, automatically with Sweave without any help of the text editor.

The following example was generated with only one file using only TeXworks, but configured to compile through R instead of using pdflatex:


This is the code:

% Test.Rnw 
% This this is not a tex file
%  run with Sweave (not with pdflatex) 

df = data.frame(Variant,Xaxis, mean,sd,se) 
dfraw <- df
colnames(df)<- c('Variant','X axis','Mean','Standard Deviation','Standard Error') 


A  \LaTeX{}  table showing a simple  {\em R} data frame: 

xtable(df, caption='This a xtable showing a data frame')

This was generated with \texttt{xtable} of  {\em R} whitin a  \LaTeX{}  (noweb) document with this raw data: 


Inserting this code in a  created  true \TeX document: 

xtable(df, caption='This a xtable showing a data frame')


Note: I make the data frame from scratch to avoid external files in the example, but of course you can change this by importing an existing file with read.csv in the R chunks.

share|improve this answer

As @zeroth pointed out, this is not a TeX question, but an orgmode question. The solution, however, is pretty simple

#+BEGIN_SRC R :colnames yes :exports results
share|improve this answer

Your Answer


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.