When using #Begin_Src R blocks one can change the code in blocks and then rerun all the code blocks in a document. Great.

However, if one does this with inline src, such as, src_R[:session *myRSession* :exports results :results raw value]{length(unique(someDataFrame$SomeVariable[someDataFrame$conditionVariable == "1"]))} one will get an output as text following this, e.g. 12. If one repeatedly evaluates all the code blocks in the file one gets an ever growning string of text "12 12 12 12 ..." Which results in one having to go in manually afterwords to clean it up.

The challenge is that in using orgmode and orgbabel to practice reproducible research by writing a technical manuscript one can have a lot of these inline statements (e.g. for every statistical test, p-values, degrees of freedom and so on).

Has anyone solved this, or have any suggestions? I have used knitr with an .Rtex file as an alternative. While this solves the in-line issue it has it's own challenges, and ideally I would like to settle on one markup format for all papers that blend code with text (and would prefer that that markup language be orgmode).

  • Have you tried :results replace header argument? That has helped me avoid appending results. – Emacs User Jun 1 '16 at 20:08

Try this:

src_R[:session *myRSession* :exports results :results raw value replace]{length(unique(someDataFrame$SomeVariable[someDataFrame$conditionVariable == "1"]))}

Which will replace the results on each run. You should see 12 only once no matter how many times you evaluate that inline function.

  • I tried this, but doesn't seem to work. If you are in the org file and you C-c C-c on the inline src block it just keeps cascading new outputs. Maybe it works when exporting? But I was hoping for something that would also work within the org file itself when I am debugging, exploring and rewriting. – brittAnderson Jun 3 '16 at 15:43
  • I am not able to recreate your problem. The other options you could try are: remove :session argument, and add :cache no argument to test if that behavior persists. – Emacs User Jun 3 '16 at 16:56
  • Thanks for the advice. I continue to have the issue, but at the moment don't have time for further debugging. Will come back here if I ever figure out what is causing the behavior, and better, how to solve it. – brittAnderson Jun 7 '16 at 13:02

Doesn't the {{{result (...)}}} construct fix your problem?

  • This is a comment, not a complete answer. – Drew May 31 '16 at 23:30
  • No. If you execute that source it will put the the raw value after the last } as text. And it will do that every time evaluated. This just pushes the prior raw value down the line and a train of them can accumulate. – brittAnderson Jun 1 '16 at 16:26
  • 1
    @Drew This is an answer. A wrong one, and lacking in explanations, but it does propose a solution. – Gilles 'SO- stop being evil' Jun 1 '16 at 19:59
  • @Gilles: If you insist. In that case, "Doesn't spaghetti and meat balls fix your problem?" might propose a solution too... I maintain what I said: it does not look like a complete answer, to me. It might be a helpful comment, though. – Drew Jun 1 '16 at 21:14

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.