[ESS] Eval region line by line - up!

Kasper Daniel Hansen khansen at stat.berkeley.edu
Sun Jan 18 03:19:19 CET 2009


Following up on an off-line question from Mark Leeds, I use the  
following commands to submit stuff from my R script buffer to the  
inferior R process

C-c C-r : select a region (which needs to be selected). I almost never  
use this command these days.
C-c C-n: submit a line and step (no need to select anything).
C-c C-f : submit a function. This can be used whenever the point  
(cursor) is inside a function
C-c C-c: kind of a block submit. In general it submits a block where  
block is anything between two returns, like

plot

plot
plot
plot

plot

The middle is a block.

I also have the following in my .emacs
(setq ess-eval-visibly-p nil)

This makes it so that the R commands from my script are not echoed in  
the inferior R buffer. The advantage is speed - does not really matter  
when you submit a single line, but I can feel it (esp. on a slower  
system) when I submit many lines of code.

Kasper


On Jan 16, 2009, at 12:43 , tyler wrote:

> 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
>
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help




More information about the ESS-help mailing list