[R] Command-line editing & history

Jeffrey Horner jeff.horner at vanderbilt.edu
Fri Mar 3 16:27:57 CET 2006

John McHenry wrote:
>    Hi all,
> Are there any plans to add more functionality to command-line editing and history editing on the command line?

Presuming you're running R from a Unix console (I'm unsure of the 
windows port, maybe?), it is sufficient, insofar as how well you like 
the GNU readline library and if it's been compiled into R:


I can even use VI style key bindings to work with historical commands: 
Typing K recalls previous commands, J goes forward through the commands. 
I can even search through the commands. Auto completion of function 
names doesn't work but file names do.

One point that was a bit of work for me to set up was automatically 
saving history. In order to do this, you must first set the environment 
variable R_HISTFILE to the location of your saved history file. Then, at 
the end of your R session, you can run:


Or better yet, put the following in your .Rprofile:

.Last <- function() savehistory(Sys.getenv("R_HISTFILE"))

> In MATLAB (I know, comparisons are odious ...), you can type "p" and up-arrow on the command line and scroll through the recently entered commands beginning with "p". This is a very useful  feature and something that I believe is not replicated in R. 
> Please correct me if I'm wrong; currently I use history(Inf) in R, search for what I want and cut and paste if I find what I'm looking for.
> Also in MATLAB, tab completion is available for directory listings and also for function name completion. Again, I'm unaware of how to do this in R. The added MATLAB  functionality makes finding files easy on the command line and it also saves the fingers on long function names. 
> Thanks,
> Jack.
> ---------------------------------
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Jeffrey Horner       Computer Systems Analyst         School of Medicine
615-322-8606         Department of Biostatistics   Vanderbilt University

More information about the R-help mailing list