[ESS] 2 things I wish ESS would do

Charles C. Berry cberry at tajo.ucsd.edu
Wed Apr 30 19:33:06 CEST 2008


Paul,

I cannot grant either wish, but I can mention a couple of workarounds.

For 1) using the 'occur' command is a useful (and sometimes 
better) substitute:

 	M-x occur RET ^> RET

will create an *Occur* buffer with all the lines from your current buffer 
that start with '>'. So if you start from an *R* buffer, you will get all 
the first lines of all commands. If you click on any line in the *Occur* 
buffer you get put in the *R* buffer with point at the command. You can 
then type RET to execute it or C-c RET to get a copy of that command 
copied to the bottom - ready to edit and execute.

You can bind the keystrokes above to a macro so you can hit one key to get 
all the commands in an *Occur* buffer. And you can use '^[>+][ ]' as the 
regexpr to get all the continuation lines, too, if you want.

For 2), there was a macro posted to this or a similar list many years back 
(apologies to the author whom I've lost track of and thanks for a terrific 
hint). It is

 	(fset 'push-line-other-window
       		"\C-@\C-e\M-w\C-n\C-a\C-xo\M->\C-y\C-m\C-xo")

I bind this to a key, and when I push that key it copies the rest of the 
line after point to the end of the buffer in the other window, then moves 
point to the next line of the current window to the position after the 
prompt. If I am working in *R* and want to copy a command to myR.R which 
is in the other window, I position point before the command and hit the 
key. To copy multiple lines, I just keep hitting the key. If I want to 
copy to the middle of myR.R, I use C-x n n to narrow to the region where I 
want the new commands to go. It also works nicely to move and execute 
commands (like debugging statements) I've commented out in myR.r back to 
*R* for execution.


HTH,

Chuck


On Wed, 30 Apr 2008, Paul Johnson wrote:

> I have 2 requests/suggestion. These reflect my experience trying to
> teach students to use R with Emacs.
>
> 1. I asked for this before, some of you said it was unnecessary for
> you.  OK.  I still  wish the command history would interleave commands
> sent from the ESS script file and commands typed at the command
> prompt.  Since some of you don't want that, I don't want that imposed
> on everybody.  But can it please be an option?  In the past, some
> other users said they would like this, but we were shouted down by
> others who said "just go read your script file if you want to see what
> you did." But that really does not help.
>
> Here's why.  In "actual practice" this is how we use Emacs, ESS and R.
> We open a file "blob.R" (or whatever) and we type whatever commands
> we want in there, and send them to the *R* session in a separate
> buffer.  Suppose we get errors in the *R* buffer.  We'd like to go
> there, recall the failed commands, and test changes.  After we fix
> errors, we are not sure what we want to do.  So we go over to the *R*
> buffer and start typing stuff in, testing commands, and such.  Maybe a
> student will make a mistake, accidentally destroy some data or such.
> It is very irritating that the command history you get with Control-up
> does not show all commands that have been executed.  It makes it
> harder to experiment, especially when students are trying to see "what
> works."  If we could Control-up to go backwards to find commands that
> came from the script file as well as from the *R* buffer, life would
> be so much happier.
>
> Of course, nobody who knows everything about R would need that
> function.  That's why I don't want it imposed on you.  I just want it
> for me & mine.
>
> 2. Can you make it easier to transfer commands that work from the *R*
> window back to the script file "blob.R" ?  Once we do hack our way to
> success in the *R* file, we want to get those commands back and save
> them.  At the current time, the only way I can find is to highlight
> the whole section of the *R* buffer, copy it over to "blob.R" and then
> delete all the lines that don't start with > and edit the rest.
>
> It would be really handy if there were some way to transfer the
> previous ten (or so)  commands from the *R* buffer back to the
> insertion point in blob.R.
>
> Or, how about click in a line in *R* and press a button to copy
> command back to script file?
>
> Again, I understand that people who know perfectly well what they are
> doing do not need features of this sort.  However, the people who are
> learning to use R need a little more consideration.
>
> I suppose you are thinking, "if your people don't know R, why are you
> bothering with Emacs-ESS?"  I'm endorsing Emacs because it is the only
> editor I know of that you can get for all platforms and I expect it
> will be maintained over the long term (because so many smart
> programmers use it). If we can teach students to use Emacs, they will
> have an editor that they can use if they want to learn to program in
> C, Java, LaTeX, or whatever else.  So, although Emacs is sometimes
> inconvenient in the short run, I expect it is beneficial in the long
> run.  Some of my Windows/Mac colleagues are endorsing an editor called
> "TINN-R" for students, or WinEdt.  I'm a conscientious objector on
> platform-limited editors...
>
> pj
>
> -- 
> Paul E. Johnson
> Professor, Political Science
> 1541 Lilac Lane, Room 504
> University of Kansas
>
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




More information about the ESS-help mailing list