Consider the following org mode document:

#+NAME: source
#+BEGIN_SRC python :cache yes
  import random
  return random.randint(3, 300)

#+RESULTS[2314024a531aeb3c9e51cd69e45adf654927e9fa]: source
: 5

#+NAME: source2
#+BEGIN_SRC python :cache yes
  import random
  return random.randint(5, 4000)

#+NAME: test
#+BEGIN_SRC sh :var v=source :var v2=source2
  echo "$v$v2"

#+RESULTS: test
: 5777

If you execute test repeatedly as is, 5777 will change each time, just always starting with a 5. This is because source has a result block, and it is cached. source2 does not have a result block, so it is not cached.

If I explicitly then execute source2, it will then have a result block and will be cached, so the output of test will always be the same.

Is there a way to configure either org mode globally or my source block(s) to produce a #+RESULT block even when they are called indirectly, as from executing test in this example?

  • Good question, but I think the answer is "no". OTOH, you could fairly easily write some code that would evaluate the two python blocks and produce a result, so that when you evaluate the third block, they would have cached values. There might be a clever way to automate that, but I haven't gone down that path far enough to say for sure.
    – NickD
    Jun 29 at 22:04


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.