Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate all code chunks below current header in emacs org mode

Tags:

emacs

org-mode

I use org mode for reproducible research and literate programming, mainly using R for computations. I'm new to emacs.

If I'm starting a new R session or my session is interrupted, I will have to rerun a number of code chunks. This is very easy with the speed commands (typing "e" to evaluate the chunk, then "n" to move to the next). I love this feature, the only problem is that my headers and subtrees are then expanded and I have to close them again to keep the page tidy.

Is there an existing feature or lisp expression to evaluate all code chunks below a header? And is it possible to do this without expanding the content below?

many thanks

For example, if the cursor were at the start of header 1, could you evaluate the code chunks under header 2 and 3 with a single command?

* header 1
** header 2

#+BEGIN_SRC R
print("hello")
#+END_SRC

** header 3

#+BEGIN_SRC R
print("world")
#+END_SRC
like image 233
Tedward Avatar asked Feb 01 '16 02:02

Tedward


People also ask

How do I use Org mode in Emacs?

To save the document, either press the save icon, or press C-x C-s, call it 1.org. Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores.

How do I run code in Org mode?

Org provides many ways to execute code blocks. C-c C-c or C-c C-v e with the point on a code block143 calls the org-babel-execute-src-block function, which executes the code in the block, collects the results, and inserts them in the buffer. By calling a named code block144 from an Org mode buffer or a table.

Does Org mode come with Emacs?

Emacs has included Org Mode as a major mode by default since 2006. Bastien Guerry is the current maintainer, in cooperation with an active development community. Since its success in Emacs, some other systems now provide functions to work with org files.


1 Answers

It sounds like you want org-babel-execute-buffer or org-babel-execute-subtree (C-c C-v s).

like image 148
John Kitchin Avatar answered Oct 14 '22 13:10

John Kitchin