DONE Visually cleaner session evaluation for R

  • State "STARTED" from "PROPOSED" 2010-08-25 Wed 10:53
  • State "PROPOSED" from "" 2010-08-23 Mon 13:59

I've made progress on using low-level ess functions for the ':session :results value' case. This results in much less noisy session evaluation, which is similar to the experience of sending R code from a .R buffer. This work is in branch ob-comint in git@github.com:dandavison/org-devel.git.

Currently, with :results value, the babel session output is very noisy:

a <- 1
b <- 2
c <- 3
> a <- 1
b <- 2
c <- 3
write.table(.Last.value, file="/tmp/org-babel-R1486ljh", sep="\t", na="nil",row.names=FALSE, col.names=FALSE, quote=FALSE)
'org_babel_R_eoe'
a <- 1
> b <- 2
> c <- 3
> write.table(.Last.value, file="/tmp/org-babel-R1486ljh", sep="\t", na="nil",row.names=FALSE, col.names=FALSE, quote=FALSE)
> 'org_babel_R_eoe'
[1] "org_babel_R_eoe"
>

This contains a write.table command and the orgbabeleoe indicator and echos all the input. The write.table and eoe are internal implementation details which it would be nice to hide from the user.

Using the new R evaluation code (branch ob-comint) for the :results value :session case, currently results in the following output:

a <- 1
b <- 2
c <- 3
> a <- 1
> b <- 2
> c <- 3

> >

I currently have not managed to make the write.table command invisible without adding extra prompt characters. The invisible command is done by `org-babel-comint-eval-invisibly'. The extra prompt chars also occur with ess-eval-region when ess-eval-visibly-p is set to nil. The invisible evaluation currently blocks until the temporary transit file to come into existence rather than watching the comint buffer as is done by `org-babel-comint-with-output'.

Old task

REJECTED re-implement R evaluation using ess-command or ess-execute

I don't have any complaints with the current R evaluation code or behaviour, but I think it would be good to use the ESS functions from a political point of view. Plus of course it has the normal benefits of an API (insulates us from any underlying changes etc). [DED]

I'll look into this. I believe that I looked at and rejected these functions initially but now I can't remember why. I agree with your overall point about using API's where available. I will take a look back at these and either switch to using the ess commands, or at least articulate under this TODO the reasons for using our custom R-interaction commands. [Eric]

ess-execute

Lets just replace org-babel-R-input-command with ess-execute.

I tried this, and although it works in some situations, I find that ess-command will often just hang indefinitely without returning results. Also ess-execute will occasionally hang, and pops up the buffer containing the results of the command's execution, which is undesirable. For now these functions can not be used. Maybe someone more familiar with the ESS code can recommend proper usage of ess-command or some other lower-level function which could be used in place of org-babel-R-input-command.

  • ess functions

    (ess-command COM &optional BUF SLEEP NO-PROMPT-CHECK)

    Send the ESS process command COM and delete the output from the ESS process buffer. If an optional second argument BUF exists save the output in that buffer. BUF is erased before use. COM should have a terminating newline. Guarantees that the value of .Last.value will be preserved. When optional third arg SLEEP is non-nil, `(sleep-for (* a SLEEP))' will be used in a few places where `a' is proportional to `ess-cmd-delay'.

    (ess-execute COMMAND &optional INVERT BUFF MESSAGE)

    Send a command to the ESS process. A newline is automatically added to COMMAND. Prefix arg (or second arg INVERT) means invert the meaning of `ess-execute-in-process-buffer'. If INVERT is 'buffer, output is forced to go to the process buffer. If the output is going to a buffer, name it BUFF. This buffer is erased before use. Optional fourth arg MESSAGE is text to print at the top of the buffer (defaults to the command if BUFF is not given.)

  • out current setup
    1. The body of the R source code block is wrapped in a function
    2. The function is called inside of a write.table function call writing the results to a table
    3. The table is read using org-table-import