I want to execute R code blocks in org-mode and export the results to a PDF/html.

Here is an example:

Some text here...

#+begin_src R :results output latex
x <- rnorm(100)
y <- x + rnorm(100)
xtable(summary(lm(y ~ x)))

I want to export the results (here, the output of xtable(summary(lm(y ~ x)))), but I can't figure out how to do it. When I export it to LaTeX or html, the text and code is exported nicely, but no table is produced in the output pdf / html file. This is the core problem I need help with. How do I get the results to export, and not just the code?

I have tried several experiments but not sure what settings I need to change.

  • If I execute the code inline (using C-c C-c), I am asked to allow for execution, and when allowed a beautiful LaTeX table is generated below the code as expected. Not sure why this is not happening when exporting to LaTeX or html.

  • I know that code is executing: If I modify the switches as below and then export to LaTeX/html, an output file is produced with appropriate name, but no results are integrated into resultant LaTeX pdf or html file. The syntax coloring is still present.

    #+begin_src R :results output latex :session *myR* :dir "." :file r-output.org
    x <- rnorm(100)
    y <- x + rnorm(100)
    xtable(summary(lm(y ~ x)))
  • 1
    I've tried to clarify what I think it is that you're trying to ask. You can roll back the changes if I misunderstood your intent.
    – Dan
    Jan 31, 2017 at 22:51
  • @Dan: Many thanks. This is certainly more readable. I'll try to keep these in mind in future. Much appreciated.
    – Shambho
    Jan 31, 2017 at 22:54

1 Answer 1


You need to use the :exports both header argument. By default, org only exports R code, not the results. From the org manual: :exports

The :exports header argument is to specify if that part of the Org file is exported to, say, HTML or LaTeX formats. Note that :exports affects only ‘src’ code blocks and not inline code.

code The default. The body of code is included into the exported file.
Example: :exports code.

results The results of evaluation of the code is included in the exported file.
Example: :exports results.

both Both the code and results of evaluation are included in the exported file.
Example: :exports both.

none Neither the code nor the results of evaluation is included in the exported file. Whether the code is evaluated at all depends on other options.
Example: :exports none.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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