Question

I have a number of Org Babel code blocks in my Library of Babel that I call sequentially quite often.

Is it possible to make an Org Babel code block that calls these other code blocks in order?

Was it helpful?

Solution

Yes, you can. Simply use :var where the parameter is the result of another block execution.

#+name: clean
#+begin_src ...
...
#+end_src

#+name: plot
#+begin_src :var data=clean
...
#+end_src

OTHER TIPS

Yes, I have several org-babel files where I do that. Here is one way to do it:

#+srcname: foo
#+begin_src python :exports code :tangle yes
  def foo():
      print "I'm foo()"
#+end_src

#+name: bar
#+begin_src python :exports code :tangle yes
  def bar():
      foo()
      print "I'm bar()'"
#+end_src

#+srcname: main
#+begin_src python :exports code :tangle yes
  foo()
  bar()
#+end_src

The output of this is a file that looks like this:

def foo():
    print "I'm foo()"

def bar():
    foo()
    print "I'm bar()'"

foo()
bar()

If the code in the org file is in a different order than what you want to generate, you can use the noweb tags to generate the code file in the order you want, like so:

#+name: bar
#+begin_src python :noweb-ref bar :tangle no
  def bar():
      foo()
      print "I'm bar()'"

#+end_src

#+srcname: foo
#+begin_src python :noweb-ref foo :tangle no
  def foo():
      print "I'm foo()"

#+end_src


#+begin_src python :noweb tangle :tangle yes

  <<foo>>
  <<bar>>

  foo()
  bar()
#+end_src

The output of tangling this is:

def foo():
    print "I'm foo()"

def bar():
    foo()
    print "I'm bar()'"

foo()
bar()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top