5

I have a simple org-mode document:

#+TITLE: My Document

#+BEGIN_SRC python :results raw :hlines yes
  return 'hello world!'
#+END_SRC

Issuing C-c C-v C-b and responding yes to the prompt to evaluate the python code block yields

#+TITLE: My Document

#+BEGIN_SRC python :results raw :hlines yes
  return 'hello world!'
#+END_SRC

#+RESULTS:
hello world!

Repeating this command yields

#+TITLE: My Document

#+BEGIN_SRC python :results raw :hlines yes
  return 'hello world!'
#+END_SRC

#+RESULTS:
hello world!
hello world!

My problem is that I don't want the old results kept once I reevaluate my src block. Is there a command to clear the old results?

  • It's buggy behaviour. The default is :results replace, but replacement doesn't work well with string output. It does work with table output. – Juancho Sep 14 '17 at 23:05
  • 1
    I think you want :results replace drawer Or just :results drawer – Melioratus Sep 15 '17 at 3:34
  • @Melioratus, Your suggestion seems to work. Why not post it as an answer? – gusbrs May 26 '18 at 23:46
  • @gusbrs - Done! Thanks for the suggestion. – Melioratus May 27 '18 at 2:40
4

Try this

org-mode provides 2 convenient header options to automatically replace the results when executing a SRC block. For contiguous results I recommend option 1. If your results will contain empty lines or your SRC block produces org syntax then use option 2.

Option 1 - Use :results replace

#+BEGIN_SRC python :results replace :hlines yes
  return 'hello world!'
#+END_SRC

#+RESULTS:
: hello world!

Option 2 - Use :results replace drawer

#+BEGIN_SRC python :results replace drawer :hlines yes
  return 'hello world!'
#+END_SRC

#+RESULTS:
:RESULTS:
hello world!
:END:

Thank you for posting your question!
Hope that helped!


This answer was tested using:
GNU Emacs 25.3.1
org-mode version: 9.1.13

  • 1
    +1 But I think the critical part here is the drawer. :results replace will work the same as :result value (default), but the OP wishes a raw output, and either :results replace drawer or :results drawer as in your comment deliver that. – gusbrs May 27 '18 at 2:52
2

:results raw does not keep track of where the results output ends, so as the comments point out, you need to use something other than raw if you want org to replace the old results with the new.

There is a function to delete results: org-babel-remove-result but that is exactly what org uses to replace results, so it suffers from the same limitation.

Your Answer

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

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