[ESS] Eval region line by line - up!

tyler tyler.smith at mail.mcgill.ca
Fri Jan 16 21:43:53 CET 2009


Ghislain Vieilledent <ghislain.vieilledent at cemagref.fr> writes:

> Dear Kasper,
>
> Thanks for your message.
> When I select a region and use C-c C-n for eval-and-step, I just have
> the first line of the selected region which is evaluated.
> I would like the whole region to be evaluated and displayed step by step
> in the *R* buffer in order to see instantaneously which line in the
> region is being evaluated. It is particularly convenient to evaluate
> long region of code.
>

This is a little tricky. You could use the following code:

(defun ess-eval-region-by-line (beg end)
  "Send the region to the R process one line at a time"
  (interactive "r")
  (goto-char beg)
  (while (< (point) end)
    (ess-eval-line-and-step)
    (while (accept-process-output 
             (get-ess-process ess-current-process-name) 0 500) )))

The trick is, if you just step through your code line by line, ess will
send the commands to R faster than R can return the output. So you end
up with the same visual output as if you'd just done an eval-region -
all the commands first, followed by all the output. 

As an ugly hack, I added a command to wait a half-second (500 ms) after
each command is passed to R. This works for commands that are quickly
evaluated, with an obvious loss of speed due to the forced waiting. I
don't think it will work for commands that take longer than 1/2 second
to evaluate. For this you'd need to increase the wait time, which slows
everything down even further.

So anyways, that addresses your primary concern. For myself, I think I
still prefer C-c C-n to this.

Cheers,

Tyler

> Regards,
>
> Ghislain
>
>
> Le jeudi 15 janvier 2009 à 20:19 -0800, Kasper Daniel Hansen a écrit :
>> C-c C-n does an eval-and-step.
>> 
>> If you are stuck with an unresponsive emacs do C-g to regain control.
>> 
>> Kasper
>> 
>> 
>> 
>> 
>> 
>> On Jan 15, 2009, at 6:48 , Ghislain Vieilledent wrote:
>> 
>> > Dear ESS-GNU/Emacs users,
>> >
>> > I would have two questions (which are linked):
>> >
>> > 1- With "C-c C-r", it is possible to evaluate a region. Nevertheless,
>> > the whole region is evaluated at the same time and the result is
>> > displayed in a block in the *R* buffer. I would prefer a line-by-line
>> > evaluation (for all the selected region), with results appearing  
>> > step by
>> > step in the *R* buffer. How can I modified my .emacs to obtain this?
>> >
>> > 2- When I have long regions of code to evaluate, my "script.r" buffer
>> > can't be written until the evaluation of the whole region has been  
>> > done.
>> > How can I release the script.r buffer to modified it while selected
>> > region is being evaluated?
>> >
>> > Thanks for your help,
>> >
>> > Ghislain Vieilledent
>> >
>> > ______________________________________________
>> > ESS-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/ess-help
>
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help

-- 
Research is what I'm doing when I don't know what I'm doing.
                                       --Wernher von Braun




More information about the ESS-help mailing list