4

I have a document in which I have named R source code blocks. These blocks are set to export the results only in the text narrative. However, I would like to include the code for these blocks in an appendix. Is there a way of subsequently re-using that code block, but with an alternate :exports flag that includes just source code?

For example, my source block might look like:

#+NAME: src:tablemaker
#+BEGIN_SRC R :exports results :colnames yes
   # Do some stuff that barfs up a dataframe / table
   ...
#+END_SRC

My results block then looks like:

#+NAME: tab:mytable
#+CAPTION: A pretty cool table
#+RESULTS[9d127a66c2787f0520a8c5140b24328357ee2ff8]: src:tablemaker

...org-table representation of my table

Then, way down in my document, I'd like to include the source of my code block, but not the results. Thank you, org-mode Jedi!

1 Answer 1

4

The answer to this turned out to be simpler than expected. This didn't work for me initially, but whatever the ephemeral problem was seems to have solved itself after an unintentional emacs reboot.

The answer was to simply put my results block above my code block, and have my code block :export both like so:

* Results
#+NAME: tab:mytable
#+RESULTS: src:foo


* Code
#+NAME: src:foo
#+BEGIN_SRC R :exports both
data.frame(1:10, rnorm(10))
#+END_SRC

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.